Setting up a new Site with Zend Framework Application/Tool
It’s been awhile since I had to set up a new site with Zend Framework, and I took the chance to play around with Zend_Tool_Project. Following the QuickStart guide, I had a site up and running in no time. But it did take me a little while to figure out how to get my modules and custom library working with the site.
Modules
To get modules enabled, you first need to create a module with Zend_Tool_Project, or you can manually create a modules directory and add the module folder there. If I wanted to add a module called cms, I would create application/modules/cms or use the command line zf create module cms.Then, In application.ini, you need to add the following two lines:
resources.modules[] =
resources.frontController.moduleDirectory = APPLICATION_PATH “/modules”
Finally, in order to load models and views, you need to add a Bootstrap.php file in the root of the modules - i.e. application/modules/cms/Bootstrap.php. In the module Bootstrap.php, place the following:
<?php
class Cms_Bootstrap extends Zend_Application_Module_Bootstrap
{
}
?>
You should be all set with modules now. Models you create within the module will use the naming convention of Cms_Model_Foo and controllers will be Cms_IndexController (when using Zend_Tool_Project and issuing zf create controller index index-action-included=1 cms, it names the controller class IndexController instead of Cms_IndexController?)
Autoloading Custom Library
The last thing I needed was to autoload my personal library which uses the naming convention Bolton_. My custom library resides in the same folder as the Zend library and is within my include path set in php.ini. In application.ini, you need to add the following line:
autoloaderNamespaces[] = \"Bolton_\"