First, I'm hoping this is just a snippet of one of your action helper's
class methods, 'cause otherwise this won't work.
That hint helped a lot. I had just dumped the code in the Action Helper
script without using any classes or methods. Don't laugh.
Second, when in your action helper, use:
$this->getResponse()
to get the response.
Perfect.
As for the issues you show below, they don't make sense, unless you're
trying to execute the above code outside the MVC environment -- for
instance, just to test the code out. I can't personally reproduce the
issue currently, which makes me think it's contextual.
I am bit concerned about the above comment. I do have the MVC environment.
Just to be sure, I am posting the code in my controller, action, layout,
view and action helper. Please advise whether the approach makes sense.
-----------------------------IndexController.php----------------------------
class IndexController extends Zend_Controller_Action
{
public function indexAction()
{
$this->view->pageTitle = "Zend Layout Example";
$this->view->bodyTitle = '<h1>Hello World!</h1>';
$this->view->bodyCopy = "<p>Lorem ipsum dolor etc.</p>";
}
}
-----------------------------IndexController.php----------------------------
----------------------Foo.php----------Action
Helper-------------------------
class BV_Controller_Action_Helper_Foo extends
Zend_Controller_Action_Helper_Abstract {
function init() {
$response = $this->getResponse();
$this->view = Zend_Layout::getMvcInstance()->getView();
$this->view->addScriptPath('../application/views/scripts');
Zend_Layout::startMvc(array('layoutPath' =>
'../application/views/layouts'));
$response->insert('sidebar',
$this->view->render('../layouts/region/sidebar.phtml'));
$response->insert('main', $this->view->render('menu/main.phtml'));
}
}
----------------------Foo.php----------Action
Helper-------------------------
-------------index.phtml-----------view
script---------------------------------
<?php echo $this->bodyTitle ;?>
<?php echo $this->bodyCopy ;?>
-------------index.phtml-----------view
script---------------------------------
-------------layout.phtml------------layout
script-----------------------------
<?php echo $this->render('menu/navigation.phtml'); ?>
<div id="content">
<?php echo $this->layout()->content ?>
</div>
<div id="sidebar">
<?php echo $this->layout()->sidebar; ?>
</div>
-------------layout.phtml------------layout
script-----------------------------
With the above code, I am trying to aggregate the various content items
like sidebar, menu and navigation in the action helper. I want to be
able to override them in the controller actions.
I never thought you would go to the extent of trying to reproduce the
issue. Thank you so much. :)
Your action helper blog post on Zend devzone was also very useful.
Regards,
--
With warm regards,
Sudheer. S
http://binaryvibes.co.in