Symfony 路由不起作用?
我正在处理现有项目。我有以下两个网址,
http://example.dev/en/course/myUserName/myCourseName/150/myChapterName/1016/page/1/?hcid=147
http://example.dev/en/course/myUserName/myCourseName/150/myChapterName/1016/page/2/?hcid=147
第二个网址工作正常,但第一个网址给我以下错误:
Unable to find a matching route to generate url for params "array ( 'action' => 'showChapter', 'module' => 'course', 'courseowner' => 'myUserName', 'coursename' => 'myCourseName', 'courseid' => '150', 'chaptername' => 'myChapterName',)".,
referer: http://example.dev/en/course/myUserName/myCourseName/150/myChapterName/1016/page/1/?hcid=147
我在routing.yml中有以下条目:
course_chapter:
url: /:sf_culture/course/:courseowner/:coursename/:courseid/:chaptername/:chapterid/:page/:pageid/
param: { module: course, action: showChapter }
requirements:
courseid: \d+
url_for():< /strong>
<?php $headchapter = ($hcid) ? '?hcid='.$hcid : '' ?>
<a href="<?php echo url_for('course/showChapter?courseowner='.$sf_params->get("courseowner").'&coursename='.$sf_params->get("coursename").'&courseid='.$sf_params->get("courseid").'&chaptername='.$chapter->getName().'&chapterid='.$chapter->getId().'&page=page&pageid=1').$headchapter ?>">
我无法理解它如何适用于第二个 URL 而不是第一个 URL。我检查了操作和视图,没有发现任何错误。
有什么想法或调试技术吗?
I am working on existing project. I have following two URLs
http://example.dev/en/course/myUserName/myCourseName/150/myChapterName/1016/page/1/?hcid=147
http://example.dev/en/course/myUserName/myCourseName/150/myChapterName/1016/page/2/?hcid=147
2nd URL is working fine but 1st URL is giving me following error:
Unable to find a matching route to generate url for params "array ( 'action' => 'showChapter', 'module' => 'course', 'courseowner' => 'myUserName', 'coursename' => 'myCourseName', 'courseid' => '150', 'chaptername' => 'myChapterName',)".,
referer: http://example.dev/en/course/myUserName/myCourseName/150/myChapterName/1016/page/1/?hcid=147
I have following entry in routing.yml:
course_chapter:
url: /:sf_culture/course/:courseowner/:coursename/:courseid/:chaptername/:chapterid/:page/:pageid/
param: { module: course, action: showChapter }
requirements:
courseid: \d+
url_for():
<?php $headchapter = ($hcid) ? '?hcid='.$hcid : '' ?>
<a href="<?php echo url_for('course/showChapter?courseowner='.$sf_params->get("courseowner").'&coursename='.$sf_params->get("coursename").'&courseid='.$sf_params->get("courseid").'&chaptername='.$chapter->getName().'&chapterid='.$chapter->getId().'&page=page&pageid=1').$headchapter ?>">
I cant understand how it is working for 2nd URL and not for first URL. I have checked the action and view and I did not find any error.
Any Idea or debugging technique ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要那样做你的链接。有一种更清洁的方法。
这样做:
如果您的路由 URL 中不存在参数,则会像
?hcid=2
一样附加该参数为什么使用 sf_params 来生成 URL 参数而不是数据库?即为什么是来自学说对象的
$sf_params->get('courseid')
而不是$course->getId()
?另外,不要使用
course/showChapter
,而是使用course_chapter
的路由ID,我建议您返回symfony手册并重新阅读路由部分。
编辑:
在您的路线定义中,您有:
url: /:sf_culture/course/:courseowner/:coursename/:courseid/:chaptername/:chapterid/:page/:pageid/
为什么页面是 a参数如果它总是相同的值,即它总是页面。
这会更好:
url: /:sf_culture/course/:courseowner/:coursename/:courseid/:chaptername/:chapterid/page/:pageid/
并且不要
chapterid 和 pageid 也需要成为
\d+
要求的一部分吗?Don't do your links like that. There is a cleaner way.
Do this instead:
If a param doesn't exist in your routing url, it'll get appended like
?hcid=2
Why are you using
sf_params
to generate the URL params and not the database? i.e why is it$sf_params->get('courseid')
and not$course->getId()
from a doctrine object?Also instead of using
course/showChapter
use the route id ofcourse_chapter
I'd advise that you go back to the symfony manual and re-read the routing section.
EDIT:
In your route definition, you have:
url: /:sf_culture/course/:courseowner/:coursename/:courseid/:chaptername/:chapterid/:page/:pageid/
why is page a parameter if it's always the same value, i.e. it's always gonna be page.
This would be better:
url: /:sf_culture/course/:courseowner/:coursename/:courseid/:chaptername/:chapterid/page/:pageid/
And don't
chapterid
andpageid
need to be part of the requirements of\d+
too?