Hi

I'm having problems setting variables into my View scripts (via a
controller) whilst using Zend_Layout.

I know what's causing the issue, I'm just unsure how to solve it!

I have an abstract action Controller that performs the following:

abstract class Core_AbstractController extends Zend_Controller_Action
{
        public function init()
        {
                $this->_response->insert('header',
App::getView()->render('etc/header.phtml'));
                $this->_response->insert('footer',
App::getView()->render('etc/footer.phtml'));
        }
}

Now, in my actual Controller i call the parent init function and then
attempt to pass a variable to the View like so:

class IndexController extends  Core_AbstractController
{
        public function init()
        {
                parent::init()
        }

        public function indexAction()
        {
                App::getView()->myNewVariable = '12345';
                echo 
App::getView()->render('templates/Admin/index/index.phtml');
        }
}

Now the problem is; in the View script $this->myNewVariable doesn't exist!
The reason being is that the response has already been set in
Core_AbstractController::init(). So by the time i create myNewVariable it's
too late!

If i was to do the following, it would work:

public function init()
{
        App::getView()->myNewVariable = '12345';
        $this->_response->insert('header',
App::getView()->render('etc/header.phtml'));
        $this->_response->insert('footer',
App::getView()->render('etc/footer.phtml'));
}

...therefore i know it's breaking in my code because the response is already
set by the time i create the View variable.

So my question is, how do i insert variables into the View after the
response has been set!?

Regards,
Jon
-- 
View this message in context: 
http://www.nabble.com/Can%27t-inject-View-variables-after-Zend_Layout-response-has-been-set-tp19344830p19344830.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to