router一方面是将url对应到不同的controller所以创建router需要放在请求处理之前的bootstrap去另一方面在view里要输出对应的url,用view helper上面页面也有例子: <a href= "<?php echo $this->url(array('username' => 'martel'), 'user') ?>">Martel</a>另见: http://framework.zend.com/manual/en/zend.view.helpers.html url($urlOptions, $name, $reset): Creates a URL string based on a named route. $urlOptions should be an associative array of key/value pairs used by the particular route.
http://framework.zend.com/manual/en/zend.controller.router.html
<?php foreach ($this->news_info as $news_item){
$route = new Zend_Controller_Router_Route_Regex(
'/index/newscenter/(\d+).html',
array(
'controller' => 'index',
'action' => 'newscenter'
),
array(
'id' => $news_item['news_id']
),
'/index/newscenter/%d.html'
);
Zend_Controller_Front::getInstance()->getRouter()->addRoute('id', $route);
?>
<li><a href="<?php print $this->url(array('controller'=>'index','action'=>'newscenter'),null,true)?>">新闻标题</a>?></li>
<?php }?>
</ul>
<a href=
"<?php echo $this->url(array('username' => 'martel'), 'user') ?>">Martel</a>另见: http://framework.zend.com/manual/en/zend.view.helpers.html
url($urlOptions, $name, $reset): Creates a URL string based on a named route. $urlOptions should be an associative array of key/value pairs used by the particular route.