Symfony2:无法使用DoctrineExtensions Mysql Year函数

时间:2013-02-22 04:39:57

标签: php mysql symfony doctrine-orm

到目前为止,我没有成功实施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();
    }
}

1 个答案:

答案 0 :(得分:5)

您是否已将YEAR功能注册到Doctrine配置?

$this->getEntityManager()->getConfiguration()->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');