我有一个考虑Zend_Controller_Router的问题。我在我的应用程序中使用模块化结构。该应用程序基于Zend-Framework。正常的路由是这样的:Zend_Router省略参数键
/modulename/actionname/
因为我一直是我的模块中使用的IndexController,这是没有必要为它提供的网址。现在我可以追加PARAMS这样的:
/modulename/actionname/paramkey/paramvalue/paramkey/paramvalue
所以这是ZF正常的,我猜。但在某些情况下,我不想在网址中提供参数。例如,我想要在网址中显示博客标题。当然,这是为SEO:
/blog/show/id/6/this-is-the-blog-title
在这种情况下,blog
是模块,show
是行动。 id
是一个参数,6
是我想要显示的博文的编号。当然是标题为6
的博文的标题。问题是,如果我做这样使用assemble()
- 方法路由器:
assemble(array('module' =>'blog',
'action' => 'show',
'id' => $row['blog_id'],
$row['blog_headline_de'] . '.html'));
的URL结果:
blog/show/id/6/0/this-is-the-blog-title.html
正如你可以看到一个0
插入作为键。但我想这个0被省略。我想这通过使用BLOGTITLE为重点,像这样:
assemble(array('module' =>'blog',
'action' => 'show',
'id' => $row['blog_id'],
$row['blog_headline_de'] . '.html' => ''));
这导致:
blog/show/id/6/this-is-the-blog-title.html/
现在0
被省略,但我有在最后的斜线。
你有没有解决方案来获得没有0
作为关键和没有结束斜杠的网址?
问候, 亚历
感谢您的答复。事情是,我不想为每件东西创建路线。你看,我在其他地方遇到了这个问题。例如在我的投资组合模块等等。所以我想知道,如果有更通用的解决方案。但如果没有,我将不得不这样做。再次感谢。 – 2010-10-30 11:38:29
你确定可以使这个规则更一般化(我将它添加到原来的答案)。 – Fge 2010-10-30 12:09:42
没关系,当然我可以这样做。问题是,我不能保证只有一个“:id”参数,但也有一些在标题前面。至少我认为这可能会发生,当我延长我的申请。但再次感谢。现在我会用这种方式。 – 2010-10-31 09:26:04