Search code examples
phpzend-frameworkubuntuinclude-path

Simple File include problem in Zend?


I have created a zend project on ubuntu which is in /var/www/student/ directory.

Now I have head.phtml file in this location:

/student/application/views/scripts/index/head.phtml

When I try to include head.phtml file in

/student/application/modules/test/views/scripts/all/index.phtml

Like this:

echo $this->partial('index/head.phtml');

It gives me following error:

Message: script 'index/head.phtml' not found in path (/var/www/student/application/modules/notification/views/scripts/) 

Including files is always a difficult job for me. How to fix this. I have to include this file in many modules then what is permanent solution for this that I should not guess the path

Thanks


Solution

  • You can add several path to look for script view files. The best way is to do it in the bootstrap file for all your common files (like head, footer, metas...).

    Just add a setupView method in your bootstrap where you deal with everything which is realted to your views :

    protected function _initView()
    {
        $view = new Zend_View();
    
        // setup your view with jquery and other stuffs... 
        // [ ... ]
    
        // add the view directory to the stack of scripts paths
        $view->addScriptPath(APPLICATION_PATH . '/views/scripts/');
    }