0

I am creating project in yii framework. I am having table as- Qbquestion QbquestionOption
-questionId -optionId -question -questionId -userId -option -isPublished -isAnswer

In QbquestionOption controller i want to access Qbquestion tables fields. I had written quesry as-

 $Question=Qbquestion::model()->findAllByAttributes(array("questionId"=>$number));

where $number is some random number. When i am using its fields as= $Question->isPublished then its giving error as "trying to get access to property of non-object" Statement var_dump($Question) is showing all record and all values of Qbquestion table. So how can i access records? Please help me

4

3 回答 3

1

findAllByAttributes返回一个对象数组。

如果您只想要一个问题,请改用findByAttributes它,那么它应该可以按您的意愿工作。

于 2012-12-15T05:09:43.117 回答
1

试试因为我不知道你的关系。试一试。如果它不起作用,我会发布其他答案。还请告诉我 isPublished 字段在哪个表中?如果它在您的标题中提到的其他表中,您需要将其更改为 echo $qRec->OtherTableRelationArrayKey->isPublished;

foreach($Question AS $qRec)
{
      echo $qRec->isPublished;
      echo "<br />";   
}
于 2012-12-15T05:10:44.277 回答
1

$Question是一个模型数组,你不能在上面调用模型函数..

你可以做的是:

 $questions = Qbquestion::model()->findAllByAttributes(array("questionId"=>$number));
 foreach($questions as $question)
    $question->isPublished()

或者你可以findByAttribute用来得到单一的结果..

于 2012-12-15T05:10:44.897 回答