【问题标题】:KnpPaginatorBundle - Fatal error: Doctrine\ORM\Query\AsIsHydrator contains 1 abstract method that must be implementedKnpPaginatorBundle - 致命错误:Doctrine\ORM\Query\AsIsHydrator 包含 1 个必须实现的抽象方法
【发布时间】:2013-08-19 12:22:24
【问题描述】:

我正在尝试将允许对实体列表进行分页的KnpPaginatorBundle 集成到我的 Symfony 项目中。

所以我照常按照 README 说明安装和设置捆绑包。

但是当我测试 KnpPaginatorBundle 示例的实现(复制过去的实现)时,我收到以下错误:

Fatal error: Class Knp\Component\Pager\Event\Subscriber\Paginate\Doctrine\ORM\Query\AsIsHydrator contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Doctrine\ORM\Internal\Hydration\AbstractHydrator::_hydrateAll) in D:\workspace\wedding\vendor\knp-components\src\Knp\Component\Pager\Event\Subscriber\Paginate\Doctrine\ORM\Query\AsIsHydrator.php on line 13

我在 Google 上没有找到任何解决方案:-/

欢迎任何帮助...谢谢

我的控制器:

/**
 * @Route("/pagin", name="pagin")
 * @Template()
 */
public function paginAction(){
    $em    = $this->get('doctrine.orm.entity_manager');
    $dql   = "SELECT c FROM LgpWeddingBundle:Contact c";
    $query = $em->createQuery($dql);

    $paginator  = $this->get('knp_paginator');
    $pagination = $paginator->paginate(
            $query,
            $this->get('request')->query->get('page', 1)/*page number*/,
            10/*limit per page*/
    );

    // parameters to template
    // return $this->render('LgpWeddingBundle:Contact:pagin.html.twig', array('pagination' => $pagination));
    return array('pagination' => $pagination);
}

Knp\Component\Pager\Event\Subscriber\Paginate\Doctrine\ORM\Query\AsIsHydrator:

class AsIsHydrator extends AbstractHydrator
{
    /**
     * Hydrates all rows from the current statement instance at once.
     */
    protected function hydrateAllData()
    {
        return $this->_stmt->fetchAll(\PDO::FETCH_ASSOC);
    }
}

Doctrine\ORM\Internal\Hydration\AbstractHydrator:

abstract class AbstractHydrator
{
    //...

    /**
     * Hydrates all rows from the current statement instance at once.
     */
    abstract protected function _hydrateAll();

    //...
}

【问题讨论】:

    标签: symfony bundle knppaginator


    【解决方案1】:

    您似乎使用的是旧版本的 Doctrin/ORM。在最新版本中它应该可以工作。这可能是 KNPPaginatorBundle 的 composer.json 的问题,但如果您想要快速修复,只需更新教义。

    出于好奇,您是否使用 Composer 安装过 KNPPaginator?如果可以,请提供您的版本。

    编辑: 我刚刚检查了 Bundles,它们对 Doctrine/ORM 没有任何依赖,所以唯一的解决方案是手动更新它。

    【讨论】:

    • 嗨,m0c,我使用了老派的方式:更新我的deps 文件并执行php bin/vendors install ;-) 我没有为KnpPaginatorBundle 指定版本及其依赖knp-components,我使用的学说版本是 2.1.5。 - 所以根据你的建议,我只需要更新我的学说版本(我假设为 2.2.x)?我希望不会有更新冲突...谢谢
    • 学说升级同时涉及太多的依赖影响/修改......解决每个依赖冲突需要花费太多时间。我将在新的 Symfony 2.3 版本上创建 POC... - 等等看;-)
    • 也许你应该利用这段时间转移到作曲家进行依赖管理,因为无论如何你都要转移到 S 2.3。
    • 是的,这也在我的计划中;-)
    猜你喜欢
    • 1970-01-01
    • 2021-09-13
    • 1970-01-01
    • 2016-04-26
    • 2016-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-09
    相关资源
    最近更新 更多