0

I want to display a mobile view instead of the normal view script.

Let's take for example this action /my_module/my_controller/my_action.

When I call it, based on some headers processing I know that user agent is a mobile device. Then I set the main layout to be a mobile-specific layout. I do that like this and it works fine: Zend_Layout::getMvcInstance()->setLayout('mobile');

But in my controller or somewhere else I want to override the default view file my_action.phtml on something like my_action_mobile.phtml.

How that could be done considering that in some of my views I am using the action helper as this: <?php echo $this->action("index", "index", "items")?> or is some of my action I have a _forward like this: $this->_forward("index", "auth", "default");

I have tried with setViewSuffix('mobile') and with several file name variants as: my_action.mobile.phtml, or setViewSuffix('mobile.phtml') and the file called my_action.mobile.phtml and others, resulting in a blank page - no error, nothing. ( i have no ideea why because it is set to display the thrown errors )

Also I have tried with contextSwitching but it disables my main layout - i do not want this - and it feels like it does not handles properly the action view helper. ( a view rendered in another )

I would appreciate any suddgestion. Thank you!

0

2 Answers 2

2

There is an awful lot of information on the subject. For starters get youself throught http://static.zend.com/topics/Mobile-web-app-with-ZF.pdf

In a nutshell, you should use ContextSwitch.

  1. You create a plugin that defines available contexts and format parameter derived from Zend_Http_UserAgent.
  2. In controller you describe which actions are eligible for those contexts.
  3. Create different views for those actions.
Sign up to request clarification or add additional context in comments.

Comments

2

You can use this to change the view from the controller
$this->render('actionName');

or, alternatively, you can call a view script directly by calling $this->renderScript('path/to/viewscript.phtml');

You can get more details on the render() and renderScript() methods from here .
Check this SO post too Assigning Values to Views when using $this->renderScript

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.