我正在使用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(),
);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。