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.

class MyFilter extends CFilter<br />

{<br />

protected function preFilter($filterChain)<br />

{<br />

// logic being applied before the action is executed<br />

return true; // false if the action should not be executed<br />

}<br />

}<br />

protected function postFilter($filterChain)<br />

{<br />

// logic being applied after the action is executed<br />

}<br />

The parameter $filterChain is of type CFilterChain which contains information about the<br />

action that is currently filtered.<br />

Controller<br />

A controller distributed as an extension should extend from CExtController, instead of<br />

CController. The main reason is because CController assumes the controller view files are<br />

located underapplication.views.ControllerID, while CExtController assumes the view files<br />

are located under theviews directory which is a subdirectory of the directory containing the<br />

controller class file. Therefore, it is easier to redistribute the controller since its view files<br />

are staying together with the controller class file.<br />

Validator<br />

A validator should extend from CValidator and implement its CValidator::validateAttribute<br />

method.<br />

class MyValidator extends CValidator<br />

{<br />

protected function validateAttribute($model,$attribute)<br />

{<br />

$value=$model->$attribute;<br />

if($value has error)<br />

$model->addError($attribute,$errorMessage);<br />

}<br />

}<br />

Console Command

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

Saved successfully!

Ooh no, something went wrong!