Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-10-2008, 08:26 AM
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-11-2008, 03:19 AM
Junior Member
 
Join Date: Oct 2007
Location: Augusta, GA
Posts: 9
Default

Hello nixnet,

You're looking for functionality of the response object. Check out:

Zend Framework: Documentation

Your probably looking for something like:
$this->getResponse()->setBody('content', $this->view->render('login/index.phtml'));

Additionally, the front controller will always try to render the corresponding .phtml file for the controller unless you tell the front controller not to, with something like:
$front->setParam('noViewRenderer', true);

Side effect of this is that you will always have to render the view. The alternative, of course, is to just have a blank corresponding .phtml file.

Hope this helps.

steve
__________________
Steve Siebert
Zend Certified Engineer
General Dynamics IT
www.get-dev.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:56 AM.