Sytrfony2.0.10注册函数YEAR来自DoctrineExtensions

时间:2017-09-11 14:26:51

标签: php symfony doctrine-orm

我被迫使用旧的symfony2.0.10并想要注册YEAR表单https://github.com/beberlei/DoctrineExtensions,所以我添加到deps并重新安装

[DoctrineExtensions]
git=https://github.com/beberlei/DoctrineExtensions

并在我的config.yml

中注册
doctrine:
dbal:
    driver:   %database_driver%
    host:     %database_host%
    port:     %database_port%
    dbname:   %database_name%
    user:     %database_user%
    password: %database_password%
    charset:  UTF8

orm:
    auto_generate_proxy_classes: %kernel.debug%
    auto_mapping: true
    dql:
        datetime_functions:
            DAY: DoctrineExtensions\Query\Mysql\Day
            MONTH: DoctrineExtensions\Query\Mysql\Month
            YEAR: DoctrineExtensions\Query\Mysql\Year

但是我有这个错误

  

致命错误:未捕获TypeError:传递给Symfony \ Component \ HttpKernel \ Debug \ ExceptionHandler :: handle()的参数1必须是Exception的实例,/ var / www / html / Symfony / vendor /中给出的Error实例symfony / src / Symfony / Component / HttpKernel / Debug / ExceptionHandler.php:57堆栈跟踪:#0 [内部函数]:Symfony \ Component \ HttpKernel \ Debug \ ExceptionHandler-> handle(Object(Error))#1 {main在第57行的/var/www/html/Symfony/vendor/symfony/src/Symfony/Component/HttpKernel/Debug/ExceptionHandler.php中抛出

编辑:这是我的代码在做错误

class NewsRepository extends EntityRepository
{
    $emConfig = $this->_em->getConfiguration();
        $emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
        $emConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Mysql\Month');


    $q = $this->_em->createQueryBuilder()->select('YEAR(news.datetime) as ye, MONTH(news.datetime) as me' )
        ->from('LittonMainBundle:News', 'news')
        ->orderBy('news.datetime', 'DESC');

我现在该怎么办?

0 个答案:

没有答案