请教大家。zend framework URL重写问题.请教下。有谁做过的。帮帮忙最近做点东西。的用zendframework实现 新闻页 伪静态有谁做过吗?加Q:65607645.谢谢:

解决方案 »

  1.   

    看一下router部分
    http://framework.zend.com/manual/en/zend.controller.router.html
      

  2.   

    <ul>
    <?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>
      

  3.   

    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.