Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony 预期的已知函数,得到';。。。在…doctor\ORM\Query\Parser.php中找不到TimeDiffFunction_Symfony_Orm_Doctrine Orm_Dql - Fatal编程技术网

Symfony 预期的已知函数,得到';。。。在…doctor\ORM\Query\Parser.php中找不到TimeDiffFunction

Symfony 预期的已知函数,得到';。。。在…doctor\ORM\Query\Parser.php中找不到TimeDiffFunction,symfony,orm,doctrine-orm,dql,Symfony,Orm,Doctrine Orm,Dql,我正在尝试实现一个自定义函数来获取两个字段上的时间差,但我不断得到错误。。。我读过类似的错误,但答案并没有真正起到帮助作用 我一直在这样做: <?php namespace Bundle\DQL; use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\AST\Functions\FunctionNode; /** * Custom DQL function returning the difference between two Da

我正在尝试实现一个自定义函数来获取两个字段上的时间差,但我不断得到错误。。。我读过类似的错误,但答案并没有真正起到帮助作用

我一直在这样做:

<?php
namespace Bundle\DQL;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;

/**
 * Custom DQL function returning the difference between two DateTime values
 * 
 * usage TIME_DIFF(dateTime1, dateTime2)
 */
class TimeDiffFunction extends FunctionNode
{
    /**
     * @var string
     */
    public $dateTime1;

    /**
     * @var string
     */
    public $dateTime2;

    public function parse(\Doctrine\ORM\Query\Parser $parser)
    {
        $parser->match(Lexer::T_IDENTIFIER);
        $parser->match(Lexer::T_OPEN_PARENTHESIS);
        $this->dateTime1 = $parser->ArithmeticPrimary();       
        $parser->match(Lexer::T_COMMA);
        $this->dateTime2 = $parser->ArithmeticPrimary();
        $parser->match(Lexer::T_CLOSE_PARENTHESIS);
    }

    public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
    {
        return 'TIME_TO_SEC(TIMEDIFF(' .
            $this->dateTime1->dispatch($sqlWalker) . ', ' .
            $this->dateTime2->dispatch($sqlWalker) .
        '))'; 
    }
}
控制器:

$em = $this->getDoctrine()->getManager();
        $detail1 = $em->getRepository('Bundle:Detail')->find(96);
        //$detail2 = $em->getRepository('Bundle:Detail')->find(138);
        $query = $em->createQuery("SELECT time_diff(eng.updatedDate, eng.updatedDate) FROM Bundle\Entity\Detail eng WHERE eng.id = :id1");
        $query->setParameter('id1', $detail1->getId());
        $entities = $query->getResult();
        die(var_dump($entities));
$query = $em->createQuery("SELECT Bundle\DQL\time_diff(eng.updatedDate, eng.updatedDate) Bundle\Entity\Detail eng WHERE eng.id = :id1");
这样做,我得到:

FatalErrorException: Error: Class 'Bundle:DQL:TimeDiffFunction' not found in C:\xampp\htdocs\EngMgmt\vendor\doctrine\orm\lib\Doctrine\ORM\Query\Parser.php line 3070
而是在控制器上执行此操作

        $query = $em->createQuery("SELECT Bundle\DQL\TimeDiff(eng.updatedDate, eng.updatedDate) FROM Bundle\Entity\Detail eng WHERE eng.id = :id1");
我得到:

[Syntax Error] line 0, col 7: Error: Expected known function, got 'Bundle\DQL\TimeDiff'
[Syntax Error] line 0, col 47: Error: Expected Doctrine\ORM\Query\Lexer::T_FROM, got '('
如果我在控制器上执行此操作:

$em = $this->getDoctrine()->getManager();
        $detail1 = $em->getRepository('Bundle:Detail')->find(96);
        //$detail2 = $em->getRepository('Bundle:Detail')->find(138);
        $query = $em->createQuery("SELECT time_diff(eng.updatedDate, eng.updatedDate) FROM Bundle\Entity\Detail eng WHERE eng.id = :id1");
        $query->setParameter('id1', $detail1->getId());
        $entities = $query->getResult();
        die(var_dump($entities));
$query = $em->createQuery("SELECT Bundle\DQL\time_diff(eng.updatedDate, eng.updatedDate) Bundle\Entity\Detail eng WHERE eng.id = :id1");
我得到:

[Syntax Error] line 0, col 7: Error: Expected known function, got 'Bundle\DQL\TimeDiff'
[Syntax Error] line 0, col 47: Error: Expected Doctrine\ORM\Query\Lexer::T_FROM, got '('

所以,问题是,我怎样才能让它工作?我真的需要它。

按照以下示例操作:

使用完全限定的类名

    dql:
       numeric_functions:
          time_diff: Bundle\DQL\TimeDiffFunction
Bundle是Bundle的一个奇怪名称。你确定那是正确的吗


选择时间差(eng.updateDate,eng.updateDate)。。。一旦正确安装,它就会工作。

捆绑包是正确的。为了避免可能出现的问题,我省略了公司的名称。星期一我会看一看祝你好运。我经常遇到他们粘贴代码然后编辑问题的帖子。有时会出现问题。谢谢你,这帮我解决了这个问题。此外,我意识到有一个“条令扩展”包包含了其中的大部分,我安装了它并在其中创建了一些我需要的其他包。