Page 1 of 1

Zend Framework changin the view

Posted: Tue Dec 04, 2007 5:17 am
by shiznatix
I am learning the Zend Framework and my first major change to it is using a different view class (not Zend_View).

So I went and got: http://framework.zend.com/wiki/display/ ... w+Ratzloff

which is great. I got everything working actually (wow) but I have a problem. If you are just using the Zend_View then you can be like:

Code: Select all

$this->view->some_var = $something_else;
Then you can access some_var in your template. Now I want to be able to do that with the Zend_View_Phptal. Currently I have to do this:

Code: Select all

$this->view = new Zend_View_Phptal;
$this->view->setScriptPath('/very/long/path/');
$this->view->test = 'value of variable';
echo $this->view->render('index.html');
I have to do that each time. How do I set it up so the view all over zend framework is the Zend_View_Phptal instead of Zend_View?

Posted: Tue Dec 04, 2007 11:21 am
by Christopher
That is only one line more than using the template library alone. What is the problem?

Posted: Tue Dec 04, 2007 11:47 am
by Luke

Code: Select all

$this->view = new Zend_View_Phptal;
$this->view->setScriptPath('/very/long/path/');
put this stuff in your bootstrap...

Code: Select all

/**
         * Prepare custom view
         */
        require_once 'Zend/View/Phptal.php';
        require_once 'Zend/Controller/Action/HelperBroker.php';
        require_once 'Zend/Controller/Action/Helper/ViewRenderer.php';
        
        $view = new Zend_View_Phptal;
        $view->setScriptPath('/very/long/path/');

        $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer;
        $viewRenderer->setView($view);
        Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
now you should be able to just use view normally and it will use your custom view instead