CDetailView,custom title

How can I give custom title at ‘cat.cat_name’?It is form a related table.

Also how not to show the html tags at values of fields?




public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		  return array('cat'=>array(self::BELONGS_TO, 'cats','cat_id' ));

	}

.....


$this->widget('zii.widgets.CDetailView', array(

	'data'=>$model,

	'attributes'=>array(

		

		'cat.cat_name',

		.....

	),

));

instead of only ‘cat.cat_name’ write:




    array(

        'name'=>'Category name',

        'value'=>'$data->cat->cat_name',

    );



Edit (added):

but the column will not be sortable

for the column to be sortable use a field that represents the FK

eg:




    array(

        'name'=>'cat_id',

        'value'=>'$data->cat->cat_name',

    );



is there a workaround to make an alias sortable in CGridView?

I have responded in the previous post…

in your model you have cat_id or something similar that is the foreign key for getting the cat_name

so you use




         array(

        'name'=>'cat_id',

        'value'=>'$data->cat->cat_name',

    );

and in the model you have the attributeLabels assigned to the fields so that the column header will be the attributeLabel you set for the field cat_id.

Hi,

I haven’t explained myself in a clear way. I have a query where in the select I have ‘…(item1+item2) AS items…’

so I want to sort by ‘items’ which is not part of my metaData but an alias…but I already sorted this type of sorting within CGridView.

Thanks anyway.

Cheers,

bettor

CDetailView

array(

'label'=>'Your Label',


'value'=>$model->cat->cat_name,

),