20.11.2014 Views

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Yii</strong> represents each console task in terms of a command. A console command is written as<br />

a class extending from CConsoleCommand.<br />

When we use the yiic webapp tool to create an initial skeleton <strong>Yii</strong> application, we may find<br />

two files under the protected directory:<br />

• yiic: this is an executable script used on Linux/Unix;<br />

• yiic.bat: this is an executable batch file used on Win<strong>do</strong>ws.<br />

In a console win<strong>do</strong>w, we can enter the following commands:<br />

cd protected<br />

yiic help<br />

This will display a list of available console commands. By default, the available commands<br />

include those provided by <strong>Yii</strong> framework (called system commands) and those developed<br />

by users for individual applications (called user commands).<br />

To see how to use a command, we can execute<br />

yiic help <br />

And to execute a command, we can use the following command format:<br />

yiic [parameters...]<br />

Creating Commands<br />

Console commands are stored as class files under the directory specified by<br />

CConsoleApplication::commandPath. By default, this refers to the directory protected/<br />

commands.<br />

A console command class must extend from CConsoleCommand. The class name must<br />

be of format XyzCommand, where Xyz refers to the command name with the first letter in<br />

upper case. For example, a sitemap command must use the class name<br />

SitemapCommand. Console command names are case-sensitive.<br />

Tip: By configuring CConsoleApplication::commandMap, one can also have command<br />

classes in different naming conventions and located in different directories.<br />

To create a new command, one often needs to override CConsoleCommand::run() or<br />

develop one or several command actions (to be explained in the next section).<br />

When executing a console command, the CConsoleCommand::run() method will be<br />

invoked by the console application. Any console command parameters will be passed to<br />

the method as well, according to the following signature of the method:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!