PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Tue Dec 04, 2007 5:17 am
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?
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Tue Dec 04, 2007 11:21 am
That is only one line more than using the template library alone. What is the problem?
(#10850)
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Tue Dec 04, 2007 11:47 am
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