简体   繁体   中英

http://example.com/fruits/apple I want to redirect to http://example.com/pen/apple

I working in zend 1 and I want to do this. If anybody call http://example.com/fruits/apple , then I want to redirect to http://example.com/pen/apple .
I am already using this code to perform this.

resources.router.routes.pen.type = "Zend_Controller_Router_Route_Static"
resources.router.routes.pen.route = "pen/apple"
resources.router.routes.pen.defaults.controller = "fruits"
resources.router.routes.pen.defaults.action = "apple"

But if I have 20 actions, then I need to do this for all actions. I want a single code to redirect to another controller with the same action in Zend Framework 1.

To achieve this result you should write a Action Plugin, then register it.

Plugin will run for each request and you can attach your functionality at a specific point in the dispatch process, here's the doc https://framework.zend.com/manual/1.10/en/zend.controller.plugins.html .

The strategy you should use is at pre dispatch, check the controller within the current request and if the controller is 'fruit' change it with 'pen'.

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