class Student extends CActiveRecord
{
public static function model($className=__CLASS__) {
return parent::model($className);
}
public function tableName() {
return 'tbl_student'; // or return '{{student}}';if you are useing tablePrefix
}
...
//--------------above can be generated by gii/giix-------------------------------------
// below is what you should do :
/**
* this method is a getter method for virtrual attribute "name"
*/
public function getName(){
return $this->firstname.$this->lastName;
}
}
then you have a readable attribute name and you can access it as
$model = Student::model()->findByPk(1);
echo $model->name ;
if you want write your name attribute you should design a setter for name:
public function setName($name){
// splite the $name into firstName and lastName
$this->firstName = $part1;
$this->lastName = $part2 ;
}
more info you can refer here :Understanding Virtual Attributes and get/set methods