geo*_*eoB 4 php mysql symfony doctrine-orm
到目前为止,我没有成功实施beberlei DoctrineExtensions.我需要MySQL Year()函数.错误是:
预期已知功能,得到'年'
所以我一定错过了什么.什么?
这是我到目前为止所获得的:
扩展安装在 ..\vendor\beberlei\lib\DoctrineExtensions
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;
Run Code Online (Sandbox Code Playgroud)
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();
}
}
Run Code Online (Sandbox Code Playgroud)
您是否已将YEAR功能注册到Doctrine配置?
$this->getEntityManager()->getConfiguration()->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
Run Code Online (Sandbox Code Playgroud)