简体   繁体   English

未知的“pagerfanta”function

[英]Unknown "pagerfanta" function

I'm using Pagerfanta bundle with Symfony 3.3.4 and Bootstrap 3;我将 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"

I then have a template inside my AppBundle which extends base.html.twig:然后我的 AppBundle 中有一个模板,它扩展了 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.好像这个 Twig function 没有包括在内,但我看不出我还需要包括什么。 Pagerfanta is in my AppKernel.php as well Pagerfanta也在我的AppKernel.php中

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. 看起来您忘记将WhiteOctoberPagerfantaBundle添加到AppKernel.php ,导致未加载PagerfantaExtension ,因此{{ pagerfanta() }}函数。

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

I guess you have a typo somewhere near rendering this template. 我猜你在渲染这个模板的地方有一个错字。 Add rendering code to your question, it should like like this. 在您的问题中添加渲染代码,它应该是这样的。

https://github.com/whiteoctober/WhiteOctoberPagerfantaBundle#rendering-pagerfantas 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,
]);

using pagerfanta with Symfony 6将 pagerfanta 与 Symfony 一起使用 6

There is no AppKernel.php in it.里面没有AppKernel.php。

If you run into the same problem using Symfony 6 then you probably forgot to install the pagerfanta-bundle or the recipe didn't add the bundle to your bundle setting: config/bundles.php如果您使用 Symfony 6 遇到同样的问题,那么您可能忘记安装pagerfanta-bundle或配方没有将捆绑包添加到您的捆绑设置: config/bundles.php

<?php

return [
    ..
    BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true],
];

For Symfony 6 you need to install these 3 packages:对于 Symfony 6,您需要安装这 3 个包:

$ composer require pagerfanta/pagerfanta
$ composer require pagerfanta/twig
$ composer require babdev/pagerfanta-bundle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM