hpaknia
hpaknia

Reputation: 3118

how to get lable of related model in Yii CDetailView?

Is there any way to access relative model lable? Here w_experience is defined in worker and because $model has not this lable, W Experience appears instead of worker model value!

    $this->widget('zii.widgets.CDetailView',
    array( 'data'=>$model, 
    'attributes'=>array( 
        array('name'=>'w_experience', 'value'=>$model->worker->w_experience==NULL?'-':$GLOBALS['worker_experience_options'][$model->worker->w_experience]),
        ), 
    'cssFile' => Yii::app()->theme->baseUrl."/css/darktable.css", )
    ); 

Upvotes: 0

Views: 1375

Answers (1)

user1233508
user1233508

Reputation:

Use

array(
  'name' => 'worker.w_experience',
  'value' => ...
),

where worker is the name of your relation.


Attribute names are usually resolved using CModel::getAttributeLabel. If your model is derived from CActiveRecord, like all database-backed models are by default, its getAttributeLabel implementation can fetch labels from related objects like this.

Upvotes: 2

Related Questions