Hello, I just want to add a new class variable for my model Users, called “fullName”, which combines the attributes first_name and last_name. I did this before but I can’t remember how…any help is appreciated, thanks.
CHtml::listData(Users::model()->findAllByAttributes(array('pid'=>$pid)),'id','fullName')) //fullName is the first name and last name together for the Users model
You can add variables to your model by just adding a member variable to your model class like so:
class MyModel extends CActiveRecord
{
public $myNewVariable;
/**
* Returns the static model of the specified AR class.
* @return TestType 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 'myModel';
}
.
.
.
After you do that you can override the afterFind() and beforeValidate() functions in CActiveRecord to set the variable and then split the variable up to push it into your database.