-1

我有两个表问题和状态。问题表与状态表有关系。问题表具有状态 ID 作为字段。我想显示actaul状态而不是它的id....那我该怎么办?

4

1 回答 1

0

假设你有正确的关系:

a) 抓取一个Qestion对象:

$question = Question::model()->findByPk(1); // e.g

上面只是一个例子,你可以使用 yii 活动记录函数的可用变量来获取对象或对象数组,但是假设你得到了 Question 模型的对象

b)您使用关系来检索活动记录对应的状态对象:

$status = $question->status; // where status is the name of the relation

c) 现在你有一个状态对象,这意味着它是你的状态模型的一个对象。您可以使用默认属性 getter 来执行以下操作:

$status->name; //where name is the attribute you want to get from your status table
于 2012-10-21T04:53:28.423 回答