Generate CFormModel with Gii ?

whether it is possible to make use CFormModel with Gii tool, such as creating models CActiveRecord.

i tried to make it but get error




Property "ModelCode.model" not defined.

D:\AppServ\www\yii\framework\gii\generators\model\ModelCode.php(172)


160     public function validateModelPath($attribute,$params)

161     {

162         if(Yii::getPathOfAlias($this->modelPath)===false)

163             $this->addError('modelPath','Model Path must be a valid path alias.');

164     }

165 

166     public function validateBaseClass($attribute,$params)




how the solution for it ?

hello ?? :)

Do you mean generate CRUD from CFormModel?

in Gii there is facilities to convert the model. whether it only refers to CActiveRecord alone or usual also to CFormModel?

You can not generate a CFormModel model using Gii.

"Model Generator" is only meant for a CActiveRecord model, because it is a tool to convert a database table structure to a model class code.

"CRUD Generator" also assumes that the target model is a CActiveRecord model.

okay, thank you

So how to generate CModelForm in YII ? If not gii then what are the steps to create it?

  • Create a new php file in models directory with the same name as the model class.

  • Write:




class MyFormModel extends CFormModel

{


}



  • Add attributes and validation rules. Don’t forget to add “safe” rule to attributes that doesn’t require validation.

  • Done :)