duanliyi5997 2017-07-13 04:41
浏览 36
已采纳

未知的“pagerfanta”功能

I'm using Pagerfanta bundle with Symfony 3.3.4 and Bootstrap 3;

    "php": ">=5.5.9",
    "components/jquery": "^3.2",
    "doctrine/doctrine-bundle": "^1.6",
    "doctrine/orm": "^2.5",
    "incenteev/composer-parameter-handler": "^2.0",
    "kriswallsmith/assetic": "^1.4",
    "oyejorge/less.php": "v1.7.0.14",
    "sensio/distribution-bundle": "^5.0.19",
    "sensio/framework-extra-bundle": "^3.0.2",
    "symfony/assetic-bundle": "^2.8",
    "symfony/monolog-bundle": "^3.1.0",
    "symfony/polyfill-apcu": "^1.0",
    "symfony/swiftmailer-bundle": "^2.3.10",
    "symfony/symfony": "3.3.*",
    "twig/twig": "^1.0||^2.0",
    "twitter/bootstrap": "^3.3",
    "white-october/pagerfanta-bundle": "^1.0"

I then have a template inside my AppBundle which extends base.html.twig:

{% extends 'base.html.twig' %}

{% block body %}
    <nav class="navbar navbar-inverse navbar-fixed-top">

...

    {% block content %}{% endblock %}

{% endblock %}

which in turn is extended by a page template:

{% extends '@AppBundle/index.html.twig' %}

{% block submenu %}
    <a href="{{ path('site_new') }}" class="btn btn-success"><i class="fa fa-plus"></i> Create</a>
{% endblock %}
{% block title %}
    Manage Sites
{% endblock %}
{% block body %}

    {{ pagerfanta(pager, 'twitter_bootstrap3') }}

{% endblock %}

Calling the template with

    $adapter = new DoctrineORMAdapter($qb);
    $pager = new Pagerfanta($adapter);
    $pager->setMaxPerPage(20);
    $pager->setCurrentPage(intval($this->getSessionPage()));

    $data = $pager->getCurrentPageResults();
    return $this->render('@AppBundle/site/index.html.twig', [
        'pager' => $pager,
        'data' => $data,
        'order' => $order,
        'form' => $form->createView()
    ]);   

However I'm getting

Unknown "pagerfanta" function.

Exception: Twig_Error_Syntax

Its as if this Twig function was not included, but I cannot see what else I need to include. Pagerfanta is in my AppKernel.php as well

  • 写回答

2条回答 默认 最新

  • dongxi2014 2017-07-17 19:54
    关注

    That looks like you've forgotten to add the WhiteOctoberPagerfantaBundle to the AppKernel.php, causing that PagerfantaExtension is not loaded, therefore the {{ pagerfanta() }} function is not defined.

    $bundles = array(
        // ...
        new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥15 关于超局变量获取查询的问题
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能