Let's say I'm tired of having to put my page template folders under views/scripts and want to just put them under views, leaving out the "scripts" part of the path. How can I alter the config of ZendFramework to permit me to do that?
+1
A:
See ZF Manual for Zend_View
and place this in your bootstrap:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initView()
{
$view = new Zend_View();
$view->setScriptPath('/some/new/path'); // overwrite any paths
$view->addScriptPath('/some/other/path'); // adds additional paths
$view->setEncoding('UTF-8');
$view->doctype('XHTML1_STRICT');
$view->headMeta()->appendHttpEquiv(
'Content-Type', 'text/html;charset=utf-8'
);
$viewRenderer =
Zend_Controller_Action_HelperBroker::getStaticHelper(
'ViewRenderer'
);
$viewRenderer->setView($view);
return $view;
}
}
or configure your Ini for use with Zend_Application_Resource_View
resources.view.encoding = "UTF-8"
resources.view.basePath = APPLICATION_PATH "/views/scripts"
...
Note that the selected basePath assumes a directory structure of:
base/path/
helpers/
filters/
scripts/
See also this tutorial by Padraic Brady.
Gordon
2010-01-13 18:35:51
Is there anyway to do this globally on a project so that I don't need to keep adding this in each class method of a controller?
Volomike
2010-01-13 18:39:44
Yes. See my addition for placing it into the Ini
Gordon
2010-01-13 18:40:19
I set your INI suggestion to "/views" instead of "/views/scripts", and then tried in the configs/application.ini under "production". It didn't work and errors out looking for "scripts".
Volomike
2010-01-13 18:47:20
Edit your question to include some of your bootstrap code then. Can't tell without seeing.
Gordon
2010-01-13 18:54:19
I just used quickstart. Nothing fancy.
Volomike
2010-01-13 19:12:55
Both options I gave you do work. If you want to set the basePath via ini, you have to use the default directory structure. If you don't want that structure, either use your own Resource_View or use initView as given above.
Gordon
2010-01-13 20:06:04
+2
A:
Hi there,
Try the following:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
// ...
protected function _initView()
{
// Initialise the view
$view = new Zend_View();
$view->addScriptPath(APPLICATION_PATH.'/views');
// set the configured view as the view to be used by the view renderer.
$renderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
$renderer->setView($view);
return $view;
}
// ...
}
The previous answer is missing the part where you set the view you have configured to have the additional script path to the View Renderer.
HTH.
rvdavid
2010-01-14 01:59:12