Recent additions to the Zend Framework command line tool <strong>zf</strong>
have made provisioning of a Zend Framework application much simpler, in addition to expanding global/system wide functionality for tools and hooks in library application hooks through the use of the zend tool providers. I will cover the creation of a Zend Framework project as well as provisioning various project resources (models, forms and database table models) with the use of the zf
tool.
First insure the zf tool installed, and is the latest version as only the most recent ZF version supports many of the operations covered in this post. I prefer maintaining my installation of Zend Framework via PEAR; the approach has eliminated many headaches around version control of the library, availability for deployments. I utilize zfcampus’ PEAR release as it packages the zf tool where others do not.
$ sudo pear channel-discover pear.zfcampus.org $ sudo pear install zfcampus/zf
At this point you should have all that is required to proceed. Next we build a ZF project utilizing the zf tool as outlined below.
$ cd ~/public_html $ zf create project Tardis Creating project at /Users/zircote/test/Tardis
Note: This command created a web project, for more information setting up your VHOST, please see docs/README This will result in the layout of the project and all supporting folders and files. Examine the docs/Readme.txt for project related configuration information.
I prefer to have all supporting classnames reflect the context of the application in which they reside; therefore I will change the class top level namespace identifier using the tool, this affords me a touch more clarity when having many projects under development and insures I dont make a mistake by having all of my project files beginning with ‘Application’:
$ zf change application.class-name-prefix Tardis Note: the name provided "Tardis" was altered to "Tardis_" for correctness. Note: All existing models will need to be altered to this new namespace by hand application.ini updated with new appnamespace Tardis_ Updating project profile '/Users/zircote/test/Tardis/.zfproject.xml'
In addition to this I also want to enable several items, which are not configured by default, layout, database, and create a table.
$ zf enable layout Layouts have been enabled, and a default layout created at /Users/zircote/test/Tardis/application/layouts/scripts/layout.phtml A layout entry has been added to the application config file. $ zf configure db-adapter 'adapter=PDO_Mysql&username=tardis&password=tardis&database=Tardis&host=localhost' A db configuration for the production section has been written to the application config file. $ zf enable form Enabling forms directory at /Users/zircote/test/Tardis/application/forms Updating project profile '/Users/zircote/test/Tardis/.zfproject.xml'
We may also specify the database settings from the zf tool as follows:
$ zf configure db-adapter 'adapter=PDO_Mysql&username=tardis&password=tardis&database=Tardis&host=localhost' A db configuration for the production section has been written to the application config file.
There are two types of model creation tools provided
- Model `zf create model name module`
- DbTable `zf create db-table`
To create a database model execute the command:
$ zf create db-table Companion companion Creating a DbTable at /Users/zircote/test/Tardis/application/models/DbTable/Companion.php Updating project profile '/Users/zircote/test/Tardis/.zfproject.xml'
The resulting class below provides the Zend_Db_Table model allowing for customization as well as additional related methods to be added.
class Tardis_Model_DbTable_Test extends Zend_Db_Table_Abstract { protected $_name = 'Tardis.test'; }
The second model type produced with the following command:
$ zf create model Moffat Creating a model at /Users/zircote/test/Tardis/application/models/Moffat.php Updating project profile '/Users/zircote/test/Tardis/.zfproject.xml'
Generates the following class may serve as a container for all non-database related material.
class Tardis_Model_Moffat { }
This is intended to serve as a high level overview of the functionality available and an outline of what it does. In future discussions I will expand on these topics as well as unit testing for models, creating custom project providers and global providers.