2012-10-20 37 views
-1

我有兩個表問題和狀態。 Quesion表與狀態表有關係。問題表的狀態爲字段。我想顯示actaul狀態而不是它的ID ....那麼我該怎麼辦?要顯示實際屬性而不是其編號

+0

你應該和狀態表連接您的問題表,並在發生狀態ID的檢索狀態名稱。但這取決於如何使用[tag:yii]。 – Vikdor

+0

thanx爲您的快速回復。我在問題控制器上有以下關係:='questionStatus'=>數組(self :: BELONGS_TO,'Qbstatus','QuestionStatusId'),那麼請你告訴我如何顯示實際狀態。 – user1761116

回答

0

假設你有正確的關係:

一)抓住一個Qestion對象:

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

上面只是一個例子,你可以得到使用對象的對象或數組yii主動記錄功能的可用變量,但假設你得到了Question模型的對象

b)您使用rela重刑以檢索相應狀態對象活動記錄:)

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

C現在你有一個狀態對象,這意味着它是你的狀態模型的對象。你可以使用默認的屬性吸氣要做到:

$status->name; //where name is the attribute you want to get from your status table 
相關問題