Holtkamp, Actually, I'm already using the classes written by Benjamin Eberlei. Thanks for the tip.
Em domingo, 16 de março de 2014 10h32min01s UTC-3, Holtkamp escreveu: > > Before writing your own, make sure you check out the "DoctrineExtensions", > written by Benjamin Eberlei. > > On how to enable them in ZF2, someone else might be able to help... > > Cheers! > On Mar 16, 2014 1:04 PM, "Diogo Domanski" <[email protected]<javascript:>> > wrote: > >> Hi all, >> >> I need to use some MySQL functions (MONTH, YEAR, SIN, ACOS, etc) in >> Doctrine2 through DQL. What I've done until now was the following (but it >> didn't work): >> >> 1. I've created a class for the MySQL function I want to use (for >> instance, ACOS): >> >> namespace MOBBase\Doctrine\ORM\Query\AST\Functions; >> >> use Doctrine\ORM\Query\AST\Functions\FunctionNode, >> Doctrine\ORM\Query\Lexer; >> >> class Acos extends FunctionNode { >> >> public $arithmeticExpression; >> >> public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { >> >> return 'ACOS(' . $sqlWalker->walkSimpleArithmeticExpression( >> $this->arithmeticExpression >> ) . ')'; >> } >> >> public function parse(\Doctrine\ORM\Query\Parser $parser) { >> >> $lexer = $parser->getLexer(); >> >> $parser->match(Lexer::T_IDENTIFIER); >> $parser->match(Lexer::T_OPEN_PARENTHESIS); >> >> $this->arithmeticExpression = >> $parser->SimpleArithmeticExpression(); >> >> $parser->match(Lexer::T_CLOSE_PARENTHESIS); >> } >> } >> >> 2. I've referenced this class in config/autoload/doctrine_orm.local.php: >> >> return array( >> 'doctrine' => array( >> 'configuration' => array( >> 'orm_default' => array( >> 'datetime_functions' => array( >> 'Month' => >> 'MOBBase\Doctrine\ORM\Query\AST\Functions\Month' >> ), >> 'numeric_functions' => array( >> 'ACOS' => >> 'MOBBase\Doctrine\ORM\Query\AST\Functions\Acos' >> ) >> ) >> ), >> ... >> >> 3. I've created a DQL query that uses the custom function. However, when >> it is executed, Doctrine triggers the following error: >> >> [Syntax Error] line 0, col 150: Error: Expected known function, got >> 'MONTH' >> >> >> Does anyone know how to correctly setup a custom MySQL function in >> Doctrine2 + ZF2? >> >> Thanks in advance >> >> -- >> You received this message because you are subscribed to the Google Groups >> "doctrine-user" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To post to this group, send email to [email protected]<javascript:> >> . >> Visit this group at http://groups.google.com/group/doctrine-user. >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "doctrine-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/doctrine-user. For more options, visit https://groups.google.com/d/optout.
