1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.tool.usage.cli">
4 <title>Using Zend_Tool On The Command Line</title>
7 The <acronym>CLI</acronym>, or command line tool (internally known as the console tool),
8 is currently the primary interface for dispatching <classname>Zend_Tool</classname>
9 requests. With the <acronym>CLI</acronym> tool, developers can issue tooling requests
10 inside the "command line window", also commonly known as a "terminal" window. This
11 environment is predominant in the *nix environment, but also has a common implementation
12 in windows with the <filename>cmd.exe</filename>, console2 and also with the Cygwin project.
16 <sect2 id="zend.tool.usage.cli.introduction">
17 <title>Introduction</title>
21 <sect2 id="zend.tool.usage.cli.installation">
22 <title>Installation</title>
24 <sect3 id="zend.tool.usage.cli.installation.download-and-go">
25 <title>Download And Go</title>
28 First download Zend Framework. This can be done by going to framework.zend.com
29 and downloading the latest release. After you've downloaded the package and placed
30 it on your system. The next step is to make the zf command available to your
31 system. The easiest way to do this, is to copy the proper files from the bin/
32 directory of the download, and place these files within the
33 <emphasis>same</emphasis> directory as the location of the <acronym>PHP</acronym>
38 <sect3 id="zend.tool.usage.cli.installation.pear">
39 <title>Installing Via Pear</title>
42 To install via PEAR, you must use the 3rd party zfcampus.org site to retrieve the
43 latest Zend Framework PEAR package. These packages are typically built within a day
44 of an official Zend Framework release. The benefit of installing via the PEAR
45 package manager is that during the install process, the ZF library will end up on
46 the include_path, and the zf.php and zf scripts will end up in a place on your
47 system that will allow you to run them without any additional setup.
50 <programlisting language="text"><![CDATA[
51 pear discover-channel pear.zfcampus.org
52 pear install zfcampus/zf
56 That is it. After the initial install, you should be able to continue on by
57 running the zf command. Go good way to check to see if it't there is to run
62 <sect3 id="zend.tool.usage.cli.installation.install-by-hand">
63 <title>Installing by Hand</title>
66 Installing by hand refers to the process of forcing the zf.php and Zend Framework
67 library to work together when they are placed in non-convential places, or at least,
68 in a place that your system cannot dispatch from easily (typical of programs in your
73 If you are on a *nix or mac system, you can also create a link from somewhere in
74 your path to the zf.sh file. If you do this, you do not need to worry about having
75 Zend Framework's library on your include_path, as the zf.php and zf.sh files will
76 be able to access the library relative to where they are (meaning the ./bin/ files
77 are ../library/ relative to the Zend Framework library).
81 There are a number of other options available for setting up the zf.php and library
82 on your system. These options revolve around setting specific environment
83 variables. These are described in the later section on "customizing the CLI
84 environement". The environment variables for setting the zf.php include_path,
85 ZF_INCLUDE_PATH and ZF_INCLUDE_PATH_PREPEND, are the ones of most interest.
90 <sect2 id="zend.tool.usage.cli.general-purpose-commands">
91 <title>General Purpose Commands</title>
93 <sect3 id="zend.tool.usage.cli.general-purpose-commands.version">
94 <title>Version</title>
97 This will show the current version number of the copy of Zend Framework the zf.php
101 <programlisting language="text"><![CDATA[
106 <sect3 id="zend.tool.usage.cli.general-purpose-commands.built-in-help">
107 <title>Built-in Help</title>
110 The built-in help system is the primary place where you can get up-to-date
111 information on what your system is capable of doing. The help system is dynamic in
112 that as providers are added to your system, they are automatically dispatchable, and
113 as such, the parameters required to run them will be in the help screen. The
114 easiest way to retrieve the help screen is the following:
117 <programlisting language="text"><![CDATA[
122 This will give you an overview of the various capabilities of the system.
123 Sometimes, there are more finite commands than can be run, and to gain more
124 information about these, you might have to run a more specialized help command.
125 For specialized help, simply replace any of the elements of the command with a "?".
126 This will tell the help system that you want more information about what commands
127 can go in place of the question mark. For example:
130 <programlisting language="text"><![CDATA[
135 The above means "show me all 'actions' for the provider 'controller'"; while the
139 <programlisting language="text"><![CDATA[
144 means "show me all providers that support the 'show' action". This works for
145 drilling down into options as well as you can see in the following examples:
148 <programlisting language="text"><![CDATA[
149 zf show version.? (show any specialties)
150 zf show version ? (show any options)
154 <sect3 id="zend.tool.usage.cli.general-purpose-commands.manifest">
155 <title>Manifest</title>
158 This will show what information is in the tooling systems manifest. This is more
159 important for provider developers than casual users of the tooling system.
162 <programlisting language="text"><![CDATA[
168 <sect3 id="zend.tool.usage.cli.general-purpose-commands.tool-configuration">
169 <title>Tool Configuration</title>
171 <para>Placeholder need docs from @beberli </para>
177 <sect2 id="zend.tool.usage.cli.project-specific-commands">
178 <title>Project Specific Commands</title>
180 <sect3 id="zend.tool.usage.cli.project-specific-commands.project">
181 <title>Project</title>
184 The project provider is the first command you might want to run. This will setup the
185 basic structure of your application. This is required before any of the other
186 providers can be executed.
189 <programlisting language="text"><![CDATA[
190 zf create project MyProjectName
194 This will create a project in a directory called ./MyProjectName. From this point
195 on, it is important to note that any subsequent commands on the command line must be
196 issued from within the project directory you had just created. So, after creation,
197 changing into that directory is required.
201 <sect3 id="zend.tool.usage.cli.project-specific-commands.module">
202 <title>Project</title>
205 The module provider allows for the easy creation of a Zend Framework module. A
206 module follows the hMVC pattern loosely. When creating modules, it will take the
207 same structure used at the application/ level, and duplicate it inside of the chosen
208 name for your module, inside of the "modules" directory of the application/
209 directory without duplicating the modules directory itself. For example:
212 <programlisting language="text"><![CDATA[
213 zf create module Blog
217 This will create a module named Blog at application/modules/Blog, and all of the
218 artifacts that a module will need.
222 <sect3 id="zend.tool.usage.cli.project-specific-commands.controller">
223 <title>Controller</title>
226 The controller provider is responsible for creating (mostly) empty controllers as
227 well as their corresponding view script directories and files. To utilize it to
228 create an 'Auth' controlller, for example, execute:
231 <programlisting language="text"><![CDATA[
232 zf create controller Auth
236 This will create a controller named Auth, specifically it will create a file at
237 application/controllers/AuthController.php with the AuthController inside.
238 If you wish to create a controller for a module, use any of the following:
241 <programlisting language="text"><![CDATA[
242 zf create controller Post 1 Blog
243 zf create controller Post -m Blog
244 zf create controller Post --module=Blog
248 Note: In the first command, 1 is the value for the "includeIndexAction" flag.
252 <sect3 id="zend.tool.usage.cli.project-specific-commands.action">
253 <title>Action</title>
256 To create an action within an existing controller:
259 <programlisting language="text"><![CDATA[
260 zf create action login Auth
261 zf create action login -c Auth
262 zf create action login --controller-name=Auth
266 <sect3 id="zend.tool.usage.cli.project-specific-commands.view">
270 To create a view outside of the normal controller/action creation, you would use
271 one of the following:
274 <programlisting language="text"><![CDATA[
275 zf create view Auth my-script-name
276 zf create view -c Auth -a my-script-name
280 This will create a view script in the controller folder of Auth.
284 <sect3 id="zend.tool.usage.cli.project-specific-commands.model">
288 The model provider is only responsible for creating the proper model files,
289 with the proper name inside the application folder. For example
292 <programlisting language="text"><![CDATA[
297 If you wish to create a model within a specific module:
300 <programlisting language="text"><![CDATA[
301 zf create model Post -m Blog
305 The above will create a 'Post' model inside of the 'Blog' module.
309 <sect3 id="zend.tool.usage.cli.project-specific-commands.form">
313 The form provider is only responsible for creating the proper form file and
314 init() method, with the proper name inside the application folder. For example:
317 <programlisting language="text"><![CDATA[
322 If you wish to create a model within a specific module:
325 <programlisting language="text"><![CDATA[
326 zf create form Comment -m Blog
330 The above will create a 'Comment' form inside of the 'Blog' module.
334 <sect3 id="zend.tool.usage.cli.project-specific-commands.database-adapter">
335 <title>DbAdapter</title>
338 To configure a DbAdapter, you will need to provide the information as a url
339 encoded string. This string needs to be in quotes on the command line.
343 For example, to enter the following information:
347 <para>adapter: Pdo_Mysql</para>
351 <para>username: test</para>
355 <para>password: test</para>
359 <para>dbname: test </para>
363 The following will have to be run on the command line:
367 <programlisting language="text"><![CDATA[
368 zf configure dbadapter "adapter=Pdo_Mysql&username=test&password=test&dbname=test"
372 This assumes you wish to store this information inside of the
373 'production' space of the application configuration file. The following will
374 demonstrate an sqlite configuration, in the 'development' section of the
375 application config file.
378 <programlisting language="text"><![CDATA[
379 zf configure dbadapter "adapter=Pdo_Sqlite&dbname=../data/test.db" development
380 zf configure dbadapter "adapter=Pdo_Sqlite&dbname=../data/test.db" -s development
384 <sect3 id="zend.tool.usage.cli.project-specific-commands.db-table">
385 <title>DbTable</title>
388 The DbTable provider is responsible for creating Zend_Db_Table
389 model/data access files for your application to consume, with the proper
390 class name, and in the proper location in the application. The two
391 important pieces of information are the <emphasis>DbTable name</emphasis>,
392 and the <emphasis>actual database table name</emphasis>. For example:
395 <programlisting language="text"><![CDATA[
396 zf create dbtable User user
397 zf create dbtable User -a user
399 // also accepts a force option to overwrite existing files
400 zf create dbtable User user -f
401 zf create dbtable User user --force-override
405 The DbTable provider is also capable of creating the proper files by
406 scanning the database configured with the above DbAdapter provider.
409 <programlisting language="text"><![CDATA[
410 zf create dbtable.from-database
414 When executing the above, it might make sense to use the pretend / "-p"
415 flag first so that you can see what would be done, and what tables can
416 be found in the database.
419 <programlisting language="text"><![CDATA[
420 zf -p create dbtable.from-database
424 <sect3 id="zend.tool.usage.cli.project-specific-commands.layout">
425 <title>Layout</title>
428 Currently, the only supported action for layouts is simply to enable them
429 will setup the proper keys in the application.ini file for the application
430 resource to work, and create the proper directories and layout.phtml file.
433 <programlisting language="text"><![CDATA[
439 <sect2 id="zend.tool.usage.cli.environment-customization">
440 <title>Environment Customization</title>
442 <sect3 id="zend.tool.usage.cli.environment-customization.storage-directory">
443 <title>The Storage Directory</title>
446 The storage directory is important so that providers may have a place to find
447 custom user generated logic that might change the way they behave. One example
448 can be found below is the placement of a custom project profile file.
451 <programlisting language="text"><![CDATA[
452 zf --setup storage-directory
456 <sect3 id="zend.tool.usage.cli.environment-customization.configuration-file">
457 <title>The Configuration File</title>
460 This will create the proper zf.ini file. This <emphasis>should</emphasis>
461 be run after <code>zf --setup storage-directory</code>. If it is not, it will
462 be located inside the users home directory. If it is, it will be located inside
463 the users storage directory.
466 <programlisting language="text"><![CDATA[
467 zf --setup config-file
471 <sect3 id="zend.tool.usage.cli.environment-customization.environment-locations">
472 <title>Environment Locations</title>
475 These should be set if you wish to override the default places where zf will
476 attempt to read their values.
485 <para>the directory this tool will look for a home directory</para>
488 <listitem><para>directory must exist</para></listitem>
491 <para>search order:</para>
494 <listitem><para>ZF_HOME environment variable</para></listitem>
495 <listitem><para>HOME environment variable</para></listitem>
496 <listitem><para>then HOMEPATH environment variable</para></listitem>
503 <para>ZF_STORAGE_DIRECTORY</para>
507 <para>where this tool will look for a storage directory</para>
510 <listitem><para>directory must exist</para></listitem>
513 <para>search order:</para>
517 <para>ZF_STORAGE_DIRECTORY environment variable</para>
520 <listitem><para>$homeDirectory/.zf/ directory</para></listitem>
527 <para>ZF_CONFIG_FILE</para>
531 <para>where this tool will look for a configuration file</para>
535 <para>search order:</para>
539 <para>ZF_CONFIG_FILE environment variable</para>
543 <para>$homeDirectory/.zf.ini file if it exists</para>
547 <para>$storageDirectory/zf.ini file if it exists</para>
555 <para>ZF_INCLUDE_PATH</para>
559 <para>set the include_path for this tool to use this value</para>
563 <para>original behavior:</para>
568 use <acronym>PHP</acronym>'s include_path to find ZF
573 <para>use the ZF_INCLUDE_PATH environment variable</para>
578 use the path ../library (relative to zf.php) to find ZF
587 <para>ZF_INCLUDE_PATH_PREPEND</para>
591 <para>prepend the current php.ini include_path with this value</para>