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.

A console command should extend from CConsoleCommand and implement its<br />

CConsoleCommand::run method. Optionally, we can override<br />

CConsoleCommand::getHelp to provide some nice help information about the command.<br />

class MyCommand extends CConsoleCommand<br />

{<br />

public function run($args)<br />

{<br />

// $args gives an array of the command-line arguments for this<br />

command<br />

}<br />

}<br />

public function getHelp()<br />

{<br />

return 'Usage: how to use this command';<br />

}<br />

Module<br />

Please refer to the section about modules on how to create a module.<br />

A general guideline for developing a module is that it should be self-contained. Resource<br />

files (such as CSS, JavaScript, images) that are used by a module should be distributed<br />

together with the module. And the module should publish them so that they can be Webaccessible.<br />

Generic Component<br />

Developing a generic component extension is like writing a class. Again, the component<br />

should also be self-contained so that it can be easily used by other developers.<br />

Utilizan<strong>do</strong> Bibliotecas de Terceiros<br />

<strong>Yii</strong> is carefully designed so that third-party libraries can be easily integrated to further<br />

extend <strong>Yii</strong>'s functionalities. When using third-party libraries in a project, developers often<br />

encounter issues about class naming and file inclusion. Because all <strong>Yii</strong> classes are<br />

prefixed with letter C, it is less likely class naming issue would occur; and because <strong>Yii</strong><br />

relies on SPL autoload to perform class file inclusion, it can play nicely with other libraries<br />

if they use the same autoloading feature or PHP include path to include class files.<br />

Below we use an example to illustrate how to use the Zend_Search_Lucene component<br />

from the Zend framework in a <strong>Yii</strong> application.<br />

First, we extract the Zend framework release file to a directory under protected/ven<strong>do</strong>rs,<br />

assumingprotected is the application base directory. Verify that the fileprotected/ven<strong>do</strong>rs/<br />

Zend/Search/Lucene.php exists.

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

Saved successfully!

Ooh no, something went wrong!