views:

84

answers:

2

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
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
Yes. See my addition for placing it into the Ini
Gordon
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
Edit your question to include some of your bootstrap code then. Can't tell without seeing.
Gordon
I just used quickstart. Nothing fancy.
Volomike
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
+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
It did help! Awesome! Thanks.
Volomike
Glad it did and you're welcome :)
rvdavid
My fault. I assumed he knew how to do this part.
Gordon