我試圖實施DQL自定義日期功能,這裏有代碼:定製DQL-功能
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.
我無法找到解決方案,我嘗試了幾個不同的命名空間,但沒有任何工作。
Symfony的版本:2.3
命名空間SwingBy \ SwingByBundle \ DQL; – Cerad
aleady嘗試過,仍然是相同的錯誤 –
不太可能。錯誤消息很明顯。確保你正在查看正確的文件。 – Cerad