-- Sudheer <[EMAIL PROTECTED]> wrote
(on Saturday, 23 August 2008, 01:38 AM +0530):
> I followed the Zend_Layout example at  
> http://akrabat.com/2007/12/11/simple-zend_layout-example/
>
> There was no problem in setting up the layout at all.
>
> Instantiating the response object and accessing its insert method in the  
> init() function of every controller is repetitious. Therefore, I try to  
> push the code in the init() function of the controller to an action 
> helper.
>
> I have an action helper foo. Below is the code in foo.php
>
> <?php
>
>        $frontController = Zend_Controller_Front::getInstance();
>
>        $response = $frontController->getResponse();
>        $response->insert('sidebar',  
> $view->render('../layouts/region/sidebar.phtml'));
>        $response->insert('main', $view->render('menu/main.phtml'));

First, I'm hoping this is just a snippet of one of your action helper's
class methods, 'cause otherwise this won't work.

Second, when in your action helper, use:

    $this->getResponse()

to get the response. 

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.


> When I view the page, I get an error
> *Fatal error*: Call to a member function insert() on a non-object in  
> *../BV/Controller/Action/Helper/Foo.php* on line *7
>
> *Line 7 in Foo.php is $response->insert('sidebar',  
> $view->render('../layouts/region/sidebar.phtml'));
>
> The error message indicates that I can't access the insert method of  
> response object. Am I allowed to access the insert method of the  
> response object in the action helper? If so, how?

-- 
Matthew Weier O'Phinney
Software Architect       | [EMAIL PROTECTED]
Zend Framework           | http://framework.zend.com/

Reply via email to