Represent Complex Attributes In Yii Model.

Hi all,

I want to define a complex attribute in yii model.Say for example student has a complex attribute which contains f_name,m_name,l_name.How can i represent it in yii model?

try this

public $f_name;

If it’s just a read-only attribute, just add a get* method.

public function getFullName()


  return $this->f_name . ' ' . $this->m_name . ' ' . $this->l_name;


echo $model->fullName;

No i want to store it in the db also.

First of all, you can store f_name, m_name and l_name as table columns.

But if for some reason this is not the case, you can do whatever you want in beforeSave() and afterFind().

For example:

public $f_name;

public $l_name;

public $m_name;

in beforeSave: $this->name = $this->f_name . ‘|’ . $this->l_name . $this->m_name;

in afterFind: list($this->f_name, $this->l_name, $this->m_name) = explode(’|’, $this->name);

Do not forget to add custom attributes to validation rules, for mass assignment.

if you want to store a value on db you can create the object and save the record…


$model = new User();

$model->f_name='your firstname';


I have a xsd file with structure,

XSD file with structure…





























how can i represent it in a yii model?

please post your final question properly…not one by one.

How can i represent this complex attribute in yii model?