未知" pagerfanta"功能

时间:2017-07-13 04:41:57

标签: php twitter-bootstrap symfony pagerfanta

我使用Pagerfanta捆绑包与Symfony 3.3.4和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"

然后我在AppBundle中有一个模板,扩展了base.html.twig:

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

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

...
    

    {% block content %}{% endblock %}

{% endblock %}

又由页面模板扩展:

{% 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 %}

使用

调用模板
    $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()
    ]);   

但是我得到了

Unknown "pagerfanta" function.

Exception: Twig_Error_Syntax

好像没有包含这个Twig功能,但我看不出还需要包含什么。 Pagerfanta也在我的AppKernel.php中

2 个答案:

答案 0 :(得分:6)

您似乎忘记将WhiteOctoberPagerfantaBundle添加到AppKernel.php,导致未加载PagerfantaExtension,因此未定义{{ pagerfanta() }}函数。< / p>

$bundles = array(
    // ...
    new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
);

答案 1 :(得分:0)

我猜你在渲染这个模板的地方有一个错字。将渲染代码添加到您的问题中,它应该是这样的。

https://github.com/whiteoctober/WhiteOctoberPagerfantaBundle#rendering-pagerfantas

$adapter = new DoctrineORMAdapter($queryBuilder);
$pagerfanta = new Pagerfanta($adapter);
    return $this->render('@YourApp/Main/example.html.twig', [
    'my_pager' => $pagerfanta,
]);