View Single Post
  #1 (permalink)  
Old 07-10-2008, 08:26 AM
nixnet nixnet is offline
Junior Member
 
Join Date: Jul 2008
Posts: 1
Default two actions using one view (Zend_Layout)

Hi there

I am missing something in ZF docs, question is: how to set content defined like this: (file layout.phtml)
Code:
<?= $this->layout()->content ?>
to render some other view?

Controller:
Code:
class RegistrationController extends Zend_Controller_Action  
{
  public function firstAction() {
   // do nothing, just proceed render the view/template
  }

  public function secondAction() {
    // TODO: render the 'first' view/template
  }
}
Currently I'm using this code in second.phtml view, which is silly:

Code:
<?php 
$this->render('registration/first.phtml'); 
?>
I wish i could just tell the Layout to render first.phtml view and do that in controller, so i don't have to create a template/view file each time, especially if one controller action should determine which view to render, depending on some conditions.

How should I do that? I have no idea, just spent a couple of hours searching the web for a solution, tried some tricks but nothing seems to work, so You guys are my last resort.

Docs tell me how to add a sidebar nad placeholders but that doesn't fit my needs. Or am I trying to do something against MVC?

Please help. I've lost a lot of time and i'm out of ideas...

EDIT:

I figured it now - don't know what went wrong when i tried it earlier. If anyone can present me more elegant solution i would be grateful.
For now i will decorate Zend_Controller_Action class and write a wrapper for this...

Controller part:
Code:
$this->_helper->layout()->content = $this->_helper->layout()->render('registration/first');
EDIT2:

sorry, it doesn't work. i left the second.phtml template intact, so it does the rendering of the first.phtml template

Last edited by nixnet : 07-10-2008 at 11:20 AM.
Reply With Quote