Hi there, I am trying to do a small webapp with yii, I created 2 table, users and area. A user is part of an area of the company (production, design, etc). I want to add in the CRUD forms a dropdown with the areas, and create update of modify the idarea in the user table. How can I do this, what changes should I do in view-controller-model files. My files area this right now:
I also don't know If the relations are ok.
models\Usuario.php
<?php class Usuario extends CActiveRecord { /** * Returns the static model of the specified AR class. * This method is required by all child classes of CActiveRecord. * @return CActiveRecord the static model class */ public static function model($className=__CLASS__) { return parent::model($className); } /** * @return string the associated database table name */ public function tableName() { return 'Usuario'; } /** * @return array validation rules for model attributes. */ public function rules() { return array( array('nombre','length','max'=>200), array('apellido','length','max'=>200), array('loginname','length','max'=>50), array('password','length','max'=>50), array('email','length','max'=>50), array('email', 'email'), array('loginname, password, email, idarea', 'required'), array('idarea', 'numerical', 'integerOnly'=>true), ); } // ----------------------------------------------------------- // Uncomment the following methods to override them if needed public function relations() { return array( 'idarea'=>array(self::HAS_ONE, 'Area', 'idarea'), ); } /* public function attributeLabels() { return array( 'authorID'=>'Author', ); } public function protectedAttributes() { return array(); } */ }
models\area.php
<?php class area extends CActiveRecord { /** * Returns the static model of the specified AR class. * This method is required by all child classes of CActiveRecord. * @return CActiveRecord the static model class */ public static function model($className=__CLASS__) { return parent::model($className); } /** * @return string the associated database table name */ public function tableName() { return 'area'; } /** * @return array validation rules for model attributes. */ public function rules() { return array( array('nombre','length','max'=>100), array('nombre', 'required'), ); } // ----------------------------------------------------------- // Uncomment the following methods to override them if needed /* public function relations() { return array( 'author'=>array(self::BELONGS_TO, 'User', 'author_id'), 'comments'=>array(self::HAS_MANY, 'Comment', 'post_id', 'with'=>'author', 'order'=>'create_time DESC'), 'tags'=>array(self::MANY_MANY, 'Tag', 'post_tag(post_id, tag_id)', 'order'=>'name'), ); } public function attributeLabels() { return array( 'authorID'=>'Author', ); } public function protectedAttributes() { return array(); } */ }
All the other files are the ones created with the CRUD command.
Thanks a lot in advance.