Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A validator will be validating that an attribute in a model is as it should be: an, integer, a date, less than a given size, ...</p> <p>Example:</p> <pre><code>public function rules() { return array( //username and password are required array('username, password', 'required'), //myInt is a number between 0 and 255 array('myInt', 'numerical', 'min'=&gt;0, 'max'=&gt; 255), ); } </code></pre> <p>The validation rules will be tested when calling <code>$model-&gt;validate()</code> or <code>$model-&gt;save()</code>. If one of the validator did not pass, then an error will be thrown to the user.</p> <p>You can know the errors thrown by calling <code>$model-&gt;getErrors()</code></p> <p>Source: <a href="http://www.yiiframework.com/wiki/56/#hh16" rel="noreferrer">Model Rules Validation</a></p> <p>The filter definition is :</p> <blockquote> <p>A filter can be applied before and after an action is executed. It can modify the context that the action is to run or decorate the result that the action generates.</p> </blockquote> <p>So basiclly it will execute some work before calling the controller method (so before rendering anything on the screen) or after the controller is done (so it could be after the datas are validated and added in the db). As example we can say:</p> <ul> <li>Check user authorizations</li> <li>Implements HTTP caching</li> <li>...</li> </ul> <p>To apply filters to actions, we need to override the CController::filters() method. The method should return an array of filter configurations. For example,</p> <pre><code>public function filters() { return array( 'postOnly + edit, create', array( 'application.filters.PerformanceFilter - edit, create', 'unit'=&gt;'second', ), ); } </code></pre> <p>Using the plus and the minus operators, we can specify which actions the filter should and should not be applied to. In the above, the <code>postOnly</code> filter will be applied to the <code>edit</code> and <code>create</code> actions, while <code>PerformanceFilter</code> filter will be applied to all actions EXCEPT <code>edit</code> and <code>create</code>. If neither plus nor minus appears in the filter configuration, the filter will be applied to all actions.</p> <p>Source: <a href="http://www.yiiframework.com/doc/api/1.1/CFilter" rel="noreferrer">Yii API about CFilter</a> and <a href="http://www.yiiframework.com/doc/guide/1.1/en/basics.controller#filter" rel="noreferrer">Yii Guide</a></p> <p>So if you want to validate some datas, then use the validators and if what you want to do is not depending on the model (ie check a user is logged in, ...) then you should implements a filter. In general the difference between a filter and a validator is pretty obvious.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload