Hi,
I’m trying to use a relation in the “view” view created by the gii crud. Seems to be a pretty common thing right? I’m currently using ternaries for my zero to many relationships so I can avoid the “Trying to get property of non-object” error. This is my current code:
'attributes'=>array(
'clientID'=>array(
'name'=>$model->getAttributeLabel('clientID'),
'value'=>$model->clientID?$model->client->client:''
),
)
but that gives me a blank spot instead of the default “Not Set” that yii puts out if it can’t find an ID.
I looked at my page source and noticed that Yii outputs a
<span class='null'>Not Set</span>
element so I modified my code above to have
'value'=>$model->taskID?$model->task->task:CHtml::tag('span', array('class'=>'null'), 'Not Set', true)
but this literally outputs all of that in the field because it generates < and > rather than the <> for the tags.
Question #1: How do I get the CHtml::tag() function to output the actual brackets for the tags or is there another function that I can put it in to achieve this?
Question #2: This seems like something very common. If I want to achieve the same result as the yii defaults while using relations, is this how I should be going about it or is there something built in that I’m missing?
Thanks,
-Nazum