0

我有一个关于 Zend_Controller_Router 的问题。我在我的应用程序中使用了模块化结构。该应用程序建立在 Zend-Framework 之上。正常的路由是这样的:

/modulename/actionname/

因为我总是在我的模块中使用 IndexController,所以没有必要在 url 中提供它。现在我可以像这样附加参数:

/modulename/actionname/paramkey/paramvalue/paramkey/paramvalue

所以这在采埃孚是正常的,我猜。但在某些情况下,我不想在 url 中提供参数键。例如,我希望在 url 中显示博客标题。当然,这是针对 SEO 的:

/blog/show/id/6/this-is-the-blog-title

在这种情况下,blog是模块,show是动作。id是一个参数,6是我要展示的博文的 id。this-is-the-blog-title当然是带有 id 的博文的标题6。问题是,如果我确实assemble()像这样使用路由器的 - 方法:

assemble(array('module' =>'blog',
               'action' => 'show', 
               'id' => $row['blog_id'],
               $row['blog_headline_de'] . '.html'));

网址导致:

blog/show/id/6/0/this-is-the-blog-title.html

如您所见, a0已作为键插入。但我希望这个 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省略了,但最后我有斜线。

您是否有任何解决方案来获取没有0as 键且没有结尾斜杠的 url?

问候,亚历克斯

4

1 回答 1

2

您可能希望为此使用自定义路由:

$router->addRoute(
    'blogentry',
    new Zend_Controller_Router_Route('blog/show/:id/:title',
                                     array('controller' => 'index', 'module' => 'blog'
                                           'action' => 'info'))
);

并使用路线作为第二个参数调用您的组装。有关更多详细信息,请参阅文档的Zend_Controller_Router_Route部分(他们甚至提供了带有assemble的示例)。

或者以更一般的方式:

$router->addRoute(
    'generalseo',
    new Zend_Controller_Router_Route(':module/:action/:id/:title',
                                     array('controller' => 'index'))
);
于 2010-10-30T10:11:39.000 回答