Zend Framework : Customizing the Directory Structure April 13, 2011Posted by Tournas Dimitrios in Zend Framework v1.10.
By default , Zend Framework expects a standard directory structure , from Zend Framework 1.8 and onwards , the proccess of creating a project is simplified with the help of an Zend command line utility ” zf ” ( zf create project nameOfProject ) . This layout contains three main folders :
- application : Contains the controllers , models and views , each in a separed folder so that the application is good organized .
- library (contains custom library files and is some cases the Zend Framework itself )
Picture of the directory structure :
This default directory structure must be maintained , to have the application run smoothly . Sometimes breaking from such a directory structure is necessary when storing the views , however . Fortunately the Zend_View can easily configured to adapt the new structure .
Each controller contains one or more actions , where each action is associated (mapped) with a view script . Let’s now pretend that we need to render a different view script from a specific controller action . The code would be :
//Inside the action function of the conroller $view->setScriptPath("absolute path to the new view dir"); $view->render("nameofview.phtml");
The setScriptPath() method forces Zend_view to change the default directory it normally uses to locate the views to the one specified using the method . The only requirement is that each controller must have its own folder within this new base directory .