Difference between #11 and #12 of
Common Yii questions

Revision #12 has been created by Maurizio Domba Cerin on Oct 18, 2011, 8:44:22 AM with the memo:

more fixes
« previous (#11) next (#13) »

Changes

Title unchanged

Common Yii questions

Category unchanged

FAQs

Yii version unchanged

Tags unchanged

yii, common, questions, beginners

Content changed

[...]
For example if you tried to get a user via active record it can be null if it does not exist, you need to check it...

<hr/>

### Why Form /
  ActiveForm is not doing ajax validation ?

#### Answer:
[...]
```php
<?php $form=$this->beginWidget('CActiveForm', array(
     'id'=>'top-websites-cr-form-id',      'enableAjaxValidation'=>true,     'clientOptions' => array(    'validateOnSubmit'=>true,   'validateOnChange'=>true,    'validateOnType'=>false,       ),
)); ?>
```
[...]
If you create your own form, and trying to do this... better create CRUD with gii, and see how it is done there!

yYou need to echo the validation results if this is an ajax request! viaBy using: ```php echo CActiveForm::validate($model);
 
``` <hr/> ### How to use find() / findByAttributes() etc.

#### Answer:
[...]
```

oOther way is to specify [CDbCriteria](http://www.yiiframework.com/doc/api/1.1/CDbCriteria "http://www.yiiframework.com/doc/api/1.1/CDbCriteria").

<hr/>
[...]
```php
Yii::app()->db->commandBuilder->createUpdateCommand(
              '{{table}}',               array(                'counter' => new CDbExpression( 'counter + :counter' , array(':counter'=>1))                  ), 
 
                new CDbCriteria(array(
 
           
), 
 
   new CDbCriteria(
 
      array(
 
"condition" => "id = :id" ,            "params" => array(             "id"=>1            )
 
   
)
 
    )
 
))             )->execute(); ```
14 0
23 followers
Viewed: 58 009 times
Version: 1.1
Category: FAQs
Written by: dckurushin
Last updated by: migajek
Created on: Oct 17, 2011
Last updated: 12 years ago
Update Article

Revisions

View all history