php – 未知“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

解决方法:

看起来您忘记将WhiteOctoberPagerfantaBundle添加到AppKernel.PHP,导致未加载PagerfantaExtension,因此未定义{{pagerfanta()}}函数.

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

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...