到目前为止,我还没有成功实现beberlei DoctrineExtensions。我需要MySQL Year()函数。错误为:
预期的已知函数,得到"年度"
所以我一定是错过了什么。什么
到目前为止,我得到的是:
扩展安装在..'vendor'beberlei'lib'DoctrineExtensions
中
app/autoload.php读取:
use Doctrine'Common'Annotations'AnnotationRegistry;
$loader = require __DIR__.'/../vendor/autoload.php';
$loader->add('DoctrineExtensions', __DIR__.'/../vendor/beberlei/lib/DoctrineExtensions');
// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
$loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
}
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
return $loader;
年度功能使用:
class ClientRepository extends EntityRepository {
public function activeStatus($year, $status) {
$em = $this->getEntityManager();
$query = $em
->createQuery('select max(Year(ct.contact_date)) CY,
c.active
from ManaClientBundle:Contacts ct
join ManaClientBundle:Client c on ct.cid = c.id
group by id')
->getResult();
return $em->createQuery("select CY, count(CY) Status from
$query where CY = $year and active = '$status'")
->getResult();
}
}
您是否已将YEAR功能注册到条令配置?
$this->getEntityManager()->getConfiguration()->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions'Query'Mysql'Year');