根据symfony2中的url的不同视图?

时间:2015-06-26 07:47:14

标签: symfony routing twig

假设我的twig文件中有以下代码。如果我在分页选项卡中单击页码,一切都工作正常如何有不同的视图。 当我点击第2页时它应该有不同的输出。例如

<p> This is page no2</p>

我的网址 http://localhost/project/web/app_dev.php/funfact/2 当我使用

检查当前网址时
    {% if app.request.attributes.get('_route') == 'funfact/2' %}
</p>    this is page no 2</p>
    {%endif%}

它没有给出上述输出。

如何将当前网址与http://localhost/project/web/app_dev.php/funfact/2

相匹配

同样在Phpstorm中它给我Alias'Sensio \ Bundle \ FrameworkExtraBundle \ Configuration \ Route'从未使用过

在我的twig view.html.twig 中  

这是第1页

<div class="row">
<ul class="pagination pagination-lg">
    <li><a href="#">&laquo;</a></li>
    <li><a href="#">1</a></li>
    <li><a href="{{ path('funfact', {'page': '2'}) }}"class="active">2</a></li>
    <li><a href="{{ path('funfact', {'page': '3'}) }}"class="active">3</a></li>
    <li><a href="#">&raquo;</a></li>
</ul>
</div>

的routing.yml:

funfact:
    path:     /funfact/{page}
    defaults: { _controller: HomeBundle:FunFact:funView, page: 1  }

控制器类

class FunFactController extends Controller
{
    /**
     * @Route("/funfact/{page}"),defaults={"page" = 1})
     */
    public function funViewAction($page)
    {
      return $this->render('HomeBundle::funfact.html.twig');
    }
}

1 个答案:

答案 0 :(得分:1)

Try this code

{% if 'funfact/2' in app.request.uri  %}
    </p>this is page no 2</p>
{% endif %}
相关问题