In the code above I’ve included only the field “USERNAME”, because the solution is for the others too . What is the access to these fields? Where should I put validation rules and so on, should I create a separate controller or something?
<?php
class users extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @return CActiveRecord the static model class
*/
//public $defaultAction='action';
public static function model($className=__CLASS__)
{
return parent::model($className);
}
//public function action() {
//$users->type=$type;
/*$this->dbConnection->createCommand(
'INSERT INTO `users` (USER_ID) VALUES('.$post->title.')')->execute();*/
//$users->save();
//$post->save();
//}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'users';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
return array(
);
}
/**
* @return array relational rules.
*/
public function relations()
{
return array(
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
);
}
}
The field 'USERNAME' is from this class "users". I have made a mistake to specify it from "userfirms", but if I specify "users" in its declaration, I am getting an error. What is the way to handle field data from the two different models.
If you have two or more model instances (from different AR classes), you can build the view like you do with a single model. You just need to use different variable names at different places. Remember to pass to the view the needed variables. In your action, you need to assign $_POST to every model's attributes.
for each of the fields, who are not from the current AR model? In our case they are USERNAME, PASSWORD, PASSWORD REPEAT, EMAIL.
Actually, the entire problem is in handling their data and validation as Yii can't understand them properly and it is logical, because they are not from the current class.
Sorry, I didn't get fully about making one class behave as a single model. Also, the part for $_POST. Could you give a little example for a view, that consists one field from one model and another field, from a different class. Use mine so that is is easier for you, if you want.
It's just unclear to me what access I do have for these fields as they are from another class and actually their validation. Should I put it in the main class's validation method in the model.