[英]How do you show the value assigned to an integer from a lookup table with yii?
在我的表单中,我是通过从表中的值填充下拉框来创建值的。
<?php echo $form->dropDownList($model,'status', CHtml::listData(Statusprospect::model()->findAll(), 'id', 'status'),array('prompt' => 'Select')); ?>
当我查看记录时,它的状态为1。 查看记录时如何使它显示值,而不是1。
当前显示该字段的查看文件代码是这样的:
<?php echo CHtml::encode($data->status); ?>
该模型确实具有定义的关系:
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(
'status0' => array(self::BELONGS_TO, 'Statusprospect', 'status'),
);
}
如何完成显示值而不是数字的显示?
现在这应该工作$data->status0->status
。
请注意,如果$ data-> status可以为null,则可能不会设置$ data-> status0-> status,因此请事先进行检查。 您可以使用
CHtml::encode(isset($data->status0->status) ? $data->status0->status : '-');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.