根据 symfony2 中 url 的不同观点?

Different views according to url in symfony2?

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

<p> This is page no2</p>

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

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

它没有给出上述输出。

如何匹配当前 url 与 http://localhost/project/web/app_dev.php/funfact/2

同样在 Phpstorm 中,它给我的别名 'Sensio\Bundle\FrameworkExtraBundle\Configuration\Route' 从未被使用过

在我的树枝里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

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

试试这个代码

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