简体   繁体   中英

Routes in Zend Framewrok

I'm just starting to work on site with CMS based on Zend. Let's say there are routes specified in routes.ini file, and one of them looks like this:

routes.news.route                = "/news/:nice/*"  
routes.news.defaults.module  = "default"   
routes.news.defaults.controller  = "news"  
routes.news.defaults.action      = "item"  
routes.news.reverse              = "/news/%s/*"

And it works just fine. But how to edit this code to disable this route if :nice will be for example page-number

So, what I want is :

routes.news.route                = "/news/(if !(:nice == page-number){ :nice}/*"

Is that even understandable ?

I don't think so one can apply if and buts within a route rule. Instead of this way you can use below mentioned solution.

  1. In your action check the value of parameter nice
  2. If it is page-number then programatically throw 404 exception.
  3. else continue execution of rest of your code.

     public function testAction() { if($this->getRequest()->getParam('nice') == 'page-number') { throw new Zend_Controller_Action_Exception('Your message here', 404); } //Rest of the Code goes here... } 

If you will call http://yourserverpath.com/index/test/nice/page-number then it will show 404 page and for any other value it will show your original page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM