简体   繁体   中英

What's the best way to add a URL parameter to switch views with Zend Framework?

I'm developing a mobile site using Zend framework, and the site has two possible output formats (WML and XHTML). I'm using the same models and controllers, and then just setting which view to render with in the controller. At the moment, this is decided on by the HTTP Accept header. This needs to be definable in the URL as well. The way I'd like to do this is with a URL like the following: http://example.com/wml/controller/action http://example.com/xhtml/controller/action

What's the best way to achieve this using the Zend Framework?

Thanks!

You need to look at Context Switching under the Action Helpers section. You can pass a format parameter via the URL and it will change the type of output that comes from the action. You should be able to easily create a Context class for WML.

So instead your URL looks like this:

http://www.example.com/controller/action/format/wml

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