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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Global options refer to those command line options that are shared by all actions in a<br />

command. For example, in a command that provides several actions, we may want every<br />

action to recognize an option named as verbose. While we can declare $verbose<br />

parameter in every action method, a better way is to declare it as a public member variable<br />

of the command class, which turns verbose into a global option:<br />

class SitemapCommand extends CConsoleCommand<br />

{<br />

public $verbose=false;<br />

public function actionIndex($type) {...}<br />

}<br />

The above code will allow us to execute a command with a verbose option:<br />

yiic sitemap index --verbose=1 --type=News<br />

Customizing Console Applications<br />

By default, if an application is created using the yiic webapp tool, the configuration for the<br />

console application will be protected/config/console.php. Like a Web application<br />

configuration file, this file is a PHP script which returns an array representing the property<br />

initial values for a console application instance. As a result, any public property of<br />

CConsoleApplication can be configured in this file.<br />

Because console commands are often created to serve for the Web application, they need<br />

to access the resources (such as DB connections) that are used by the latter. We can <strong>do</strong><br />

so in the console application configuration file like the following:<br />

return array(<br />

......<br />

'components'=>array(<br />

'db'=>array(<br />

......<br />

),<br />

),<br />

);<br />

As we can see, the format of the configuration is very similar to what we <strong>do</strong> in a Web<br />

application configuration. This is because both CConsoleApplication and CWebApplication<br />

share the same base class.<br />

Segurança<br />

Cross-site Scripting Prevention

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

Saved successfully!

Ooh no, something went wrong!