PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Project Specific Commands

Project

The project provider is the first command you might want to run. This will setup the basic structure of your application. This is required before any of the other providers can be executed.

zf create project MyProjectName

This will create a project in a directory called ./MyProjectName. From this point on, it is important to note that any subsequent commands on the command line must be issued from within the project directory you had just created. So, after creation, changing into that directory is required.

Module

The module provider allows for the easy creation of a Zend Framework module. A module follows the hMVC pattern loosely. When creating modules, it will take the same structure used at the application/ level, and duplicate it inside of the chosen name for your module, inside of the "modules" directory of the application/ directory without duplicating the modules directory itself. For example:

zf create module Blog

This will create a module named Blog at application/modules/Blog, and all of the artifacts that a module will need.

Controller

The controller provider is responsible for creating (mostly) empty controllers as well as their corresponding view script directories and files. To utilize it to create an 'Auth' controlller, for example, execute:

zf create controller Auth

This will create a controller named Auth, specifically it will create a file at application/controllers/AuthController.php with the AuthController inside. If you wish to create a controller for a module, use any of the following:

zf create controller Post 1 Blog
zf create controller Post -m Blog
zf create controller Post --module=Blog

Note: In the first command, 1 is the value for the "includeIndexAction" flag.

Action

To create an action within an existing controller:

zf create action login Auth
zf create action login -c Auth
zf create action login --controller-name=Auth

View

To create a view outside of the normal controller/action creation, you would use one of the following:

zf create view Auth my-script-name
zf create view -c Auth -a my-script-name
            

This will create a view script in the controller folder of Auth.

Model

The model provider is only responsible for creating the proper model files, with the proper name inside the application folder. For example

zf create model User

If you wish to create a model within a specific module:

zf create model Post -m Blog

The above will create a 'Post' model inside of the 'Blog' module.

Form

The form provider is only responsible for creating the proper form file and init() method, with the proper name inside the application folder. For example:

zf create form Auth

If you wish to create a model within a specific module:

zf create form Comment -m Blog

The above will create a 'Comment' form inside of the 'Blog' module.

DbAdapter

To configure a DbAdapter, you will need to provide the information as a url encoded string. This string needs to be in quotes on the command line.

For example, to enter the following information:

  • adapter: Pdo_Mysql

  • username: test

  • password: test

  • dbname: test

The following will have to be run on the command line:

zf configure dbadapter "adapter=Pdo_Mysql&username=test&password=test&dbname=test"

This assumes you wish to store this information inside of the 'production' space of the application configuration file. The following will demonstrate an sqlite configuration, in the 'development' section of the application config file.

zf configure dbadapter "adapter=Pdo_Sqlite&dbname=../data/test.db" development
zf configure dbadapter "adapter=Pdo_Sqlite&dbname=../data/test.db" -s development

DbTable

The DbTable provider is responsible for creating Zend_Db_Table model/data access files for your application to consume, with the proper class name, and in the proper location in the application. The two important pieces of information are the DbTable name, and the actual database table name. For example:

zf create dbtable User user
zf create dbtable User -a user

// also accepts a force option to overwrite existing files
zf create dbtable User user -f
zf create dbtable User user --force-overwrite

The DbTable provider is also capable of creating the proper files by scanning the database configured with the above DbAdapter provider.

zf create dbtable.from-database

When executing the above, it might make sense to use the pretend / "-p" flag first so that you can see what would be done, and what tables can be found in the database.

zf -p create dbtable.from-database

Layout

Currently, the only supported action for layouts is simply to enable them will setup the proper keys in the application.ini file for the application resource to work, and create the proper directories and layout.phtml file.

zf enable layout

Zend Framework