Symfony4:路由引用另一个页面

Symfony4: routing references another page

从Symfony 3.4更新到4.4并验证运行后,发现input.html.twig中的app_hq_article_trendtag指向了另一个页面。参考目的地是 ArticleController 的 B。 从 Symfony 3.4 开始,它运行良好。 你是不是设置有误?如果除了命令之外还有其他要检查的东西 请告诉我。

我也改了一些代码,检查了运行情况。 将ArticleController的@Template("@AppBundle/Hq/Article/index.html.twig")改成另一个页面->显示另一个页面。 将 ArticleController 的 @Template("@AppBundle/Hq/Article/trendTag.html.twig") 更改为另一个页面-> 无变化 将 input.html.twig 的 app_hq_article_trendtag 更改为另一页-> 显示另一页。

文章控制器

 * @Route("/hq")
 */
class ArticleController extends BaseArticleController
{
    protected $indexRoute = "app_hq_article_index";

    protected function getInputTemplate($articleType)
    {
        return sprintf("@AppBundle/Hq/%s/input.html.twig", ucfirst($articleType));
    }

    /**
     * @Method("GET")
     * @Route("/article/")
     *
     * @Template("@AppBundle/Hq/Article/index.html.twig")
     */
    public function indexAction(Request $request)
    {
        return parent::indexAction($request);
    }
    /**
     * @Method("GET")
     * @Route("/article/trendtag")
     *
     * @Template("@AppBundle/Hq/Article/trendTag.html.twig")
     */
    public function trendTagAction(Request $request)
    {
        return parent::trendTagAction($request);
    }

Brandevent/input.html.twig

{{ form_start(form) }}
        <div class="formGroup trendTags" data-prototype="{{ macros.trendTagForm(form.trendTags.vars.prototype)|e }}" data-index="{{ ec_tag_contents|length }}">
            <label>Tag</label>
            <button type="button" class="add btn">Add</button>
            <ul class="trend-tag-list2" {% if not ec_tag_contents|default %} style="display:none"{% endif %} id="trendTagsWrap">
                {% for tag in ec_tag_contents|default %}
                    <li>
                        <div class="tagForm">
                            <div class="input-trendtag-display-name">&nbsp;{{ tag.name }}</div>
                            <div class="input-trendtag-display-term">({{ tag.str_tag_display }}  {{ tag.str_term }})</div>
                            <br>
                            {% for category in tag.categories|split(',') %}
                            <div class="tag-form__category-sticker" name="{{ category }}">{{ category }}</div>
                            {% endfor %}
                            <button class="removeTrendTag"><i class="icon-remove"></i></button>
                        </div>
                        <div id="brandevent_trendTags_{{ loop.index0 }}">
                            <input type="hidden" id="brandevent_trendTags_{{ loop.index0 }}_trendTagId" name="brandevent[trendTags][{{ loop.index0 }}][trendTagId]" required="required" value="{{ tag.tag_id }}">

                        </div>
                    </li>
                {% endfor %}
                {% do form.trendTags.setRendered(true) %}
            </ul>
        </div>

{{ form_end(form) }}

      //Problem part
      {% set q = app.request.query.get("q")|default({}) %}
      {% set trendTagUrl = path("app_hq_article_trendtag", {"q[sex]": q.sex|default(0), "q[brand_id]": q.brand_id|default(), "q[del_flg]": 0}) %}
      <div id="trendTagDialog" title="Tag Select" data-url="{{ trendTagUrl }}">
      </div>

命令

$ php bin/console debug:router app_hq_article_trendtag
+--------------+--------------------------------------------------------------------+
| Property     | Value                                                              |
+--------------+--------------------------------------------------------------------+
| Route Name   | app_hq_article_trendtag                                   |
| Path         | /admin/hq/article/trendtag                                         |
| Path Regex   | #^/admin/hq/article/trendtag$#sD                                   |
| Host         | ANY                                                                |
| Host Regex   |                                                                    |
| Scheme       | http                                                               |
| Method       | ANY                                                                |
| Requirements | NO CUSTOM                                                          |
| Class        | Symfony\Component\Routing\Route                                    |
| Defaults     | _controller: AppBundle:Hq\Article:trendTag                  |
| Options      | compiler_class: Symfony\Component\Routing\RouteCompiler            |
| Callable     | AppBundle\Controller\Hq\ArticleController::trendTagAction |
+--------------+--------------------------------------------------------------------+

如果你改变函数的顺序就可以正常工作 当你尝试获取路由 /hq/article/trendtag 时,它将获取第一个找到它的 /hq/article,因此你可以像下面的代码一样更改它 该文件是从顶部读取的,当它在/article/trendtag之前找到路由“/article/”时,即使您要获取/article/trendtag,他也只考虑找到的/article/第一部分它。

* @Route("/hq")
 */
class ArticleController extends BaseArticleController
{
    protected $indexRoute = "app_hq_article_index";

    protected function getInputTemplate($articleType)
    {
        return sprintf("@AppBundle/Hq/%s/input.html.twig", ucfirst($articleType));
    }
 /**
     * @Method("GET")
     * @Route("/article/trendtag")
     *
     * @Template("@AppBundle/Hq/Article/trendTag.html.twig")
     */
    public function trendTagAction(Request $request)
    {
        return parent::trendTagAction($request);
    }
    /**
     * @Method("GET")
     * @Route("/article/")
     *
     * @Template("@AppBundle/Hq/Article/index.html.twig")
     */
    public function indexAction(Request $request)
    {
        return parent::indexAction($request);
    }