4

到目前为止,我在实施 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();
    }
}
4

1 回答 1

5

您是否已将 YEAR 函数注册到 Doctrine 配置中?

$this->getEntityManager()->getConfiguration()->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
于 2013-02-22T08:48:32.263 回答