0

我正在尝试为 DQL 实现自定义 DATE 函数,这里有代码:

namespace SwingBy\SwingByBundle\DQL; 

use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;

/**
 * Date  ::= "DATE" "(" ArithmeticPrimary ")"
 */

class Date extends FunctionNode {

    public $dateTimeExpression = null;

    public function parse(\Doctrine\ORM\Query\Parser $parser){

         $parser->match(Lexxer::T_IDENTIFIER);
         $parser->match(Lexxer::T_OPEN_PARENTHESIS);
         $this->dateTimeExpression = $parser->ArithmeticPrimary();
         $parser->match(Lexxer::T_CLOSE_PARENTHESIS);
    }

    public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker){

        return "DATE(" . $this->dateTimeExpression . ")";
    }
}

这是 config.yml 中的配置:

doctrine:
    orm:
        dql:
            datetime_functions:
                date: SwingBy\SwingByBundle\DQL\Date

这是错误:

The autoloader expected class "SwingBy\SwingByBundle\DQL\Date" to be defined in file 
"/Applications/MAMP/htdocs/swingby_dev2.3/src/SwingBy/SwingByBundle/DQL/Date.php". The 
file was found but the class was not in it, the class name or namespace probably has a   
typo.

I am not able to find a solution, I've tried several different namespaces but nothing worked.

Symfony-version: 2.3

4

1 回答 1

0

根据文档http://symfony.com/fr/doc/current/cookbook/doctrine/custom_dql_functions.html

doctrine:
    orm:
        entity_managers:
            default:
                dql:
                    datetime_functions:
                        date: SwingBy\SwingByBundle\DQL\Date

和/或尝试添加反斜杠

日期:\SwingBy\SwingByBundle\DQL\Date

于 2013-08-26T08:21:17.697 回答