Yii Add validation for selected fields

On Controller file

$model = new Model_Name();
$model->field_name = $_POST[‘fname’];
echo CHtml::errorSummary($model);

On Model Files Under rule array

array(‘field name list’, ‘required’,’on’ => ‘Articlereview’),

Posted in Yii-php | Leave a comment

Add condition on model

Add condition in Model.

public function relations()

return array(

ANY_Name => array(self::MANY_MANY,MODEL_NAME) // this is for common
ANY_Name => array(self::MANY_MANY,MODEL_NAME, ‘on’=>’ANY_Name.fied_name = 1’) // this is for conditional



Posted in Yii-php | Leave a comment

Yii web application development

–> Create Your First Application.

Download Yii Framework.


Download PHP Server




Step of yii installation if you have a server XAMP.

put your yii(extract) folder under xamp/htdoc/

if wamp than www/ folder.

Now open cmd go to www or htdoc path for example cd (c:\xamp\htdoc\yii\framework  OR c:\wamp\www\yii\framework )

than type yiic webapp ../../testyii (press enter)

Give y + enter

now you first project created.

run. http://localhost/testyii.

Share here if you have any problem or questions.

Posted in Yii-php | 3 Comments