2012-10-25 41 views
1

我是Zend Framework的新手。我有一个页面,就是:避免在Zend Framework路由中使用“/ index/index”两次

http://localhost/demo/public/index/index/catid/art 

我想改变这种状况到

http://localhost/demo/public/art 

我不知道该怎么做。

另外,它为什么要把index两次?即使我的分页有,如:

http://localhost/demo/public/index/index/page/2 

在我看来有点烦人。我想分页是

http://localhost/demo/public/page/2 

有没有办法做到这一点?谢谢!

+0

你真的需要由具有“/演示/演示/公/”,在每一个URL前缀来迷惑你的问题在你的控制器的网页PARAM?我不得不假设你的baseURL从'/ demo/demo/public /'开始。 – Layke

+0

好的,我修好了。 – raygo

回答

2

缺省路由的工作原理是利用:

/module/controller/action

所以,如果你调用一个模块“默认”,并称之为“指数”你的控制器,以及所谓的“指数”的操作,那么最指代具体的行动冗长的方法是:

/module/controller/action

为了建立一个路线,你可以使用:

$route = new Zend_Controller_Router_Route(
      'page/:page', 
      array(
       'module' => 'default' 
       'controller' => 'index', 
       'action' => 'index' 
      ), 
      array(
       'page' => '\d+' 
      ) 
     ); 

然后,您可以得到使用

$this->getRequest->getParam("page");

+0

它像分页的魅力一样工作。第一个例子我该怎么做?隐藏参数? – raygo

+0

你可以找出这一个。 :)我帮助你解决了更困难的例子。找到http://framework.zend.com/manual/1.12/en/zend.controller.router.html#zend.controller.router.routes.static – Layke