简体   繁体   English

生成的Slug覆盖Symfony2控制器链接

[英]Generated Slug Overriding Symfony2 Controller Links

I am having a few problems with my Routing with regards to my new customised CMS. 关于新的自定义CMS,我的路由遇到一些问题。 My CMS can generate custom slugs for a page and I have set up the route for this to work. 我的CMS可以为页面生成自定义的标签,并且我已经为此设置了路由。 It does so perfectly. 它是如此完美。 However, I also have a help and advice section that has a different URL and is a static page. 但是,我也有一个帮助和建议部分,该部分具有不同的URL,并且是静态页面。 My routing.yml looks like this: - 我的routing.yml看起来像这样:-

helpadvice:
        path:       /help-advice
        defaults:   { _controller: FrontBundle:Posts:helpadvice }

frontpage:
    pattern:    /{slug}
    defaults:   { _controller: FrontBundle:Pages:livepages }
    requirements:
        slug:   .+

This should work fine but when I visit the page I get an error that it is looking for the page on the database using the slug. 这应该可以正常工作,但是当我访问该页面时,我得到一个错误,即它正在使用该插件在数据库中查找该页面。

Can anyone help me solve this? 谁能帮我解决这个问题?

The order of the routes matter. 路线的顺序很重要。 The frontpage route is a catch all route , so that should be the very last one and you have to move it there. frontpage路线是frontpage路线,因此应该是最后一条路线 ,您必须将其移到那里。 You can check the order with the router:debug command. 您可以使用router:debug命令检查顺序。

Could it be that your routing is wrong? 可能是您的路由错误吗?

/{slug} and /help-device are the same route. / {slug}和/ help-device是同一路径。 Your symfony is thinking "help-device" is a slug. 您的symfony认为“帮助设备”是一种a。 Just change /help-advice for /help/advice (for example) or the /{slug} for /slug/{slug} (or something) and check if that solves your problem. 只需将/ help / advice更改为/ help-advice(例如),将/ slug / {slug}更改为/ {slug}(或其他内容),然后检查是否可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM