Yii,使用 with() 方法调用时 findAll 出错. [英] Yii, Error in findAll, when called using with() method.
问题描述
我正在上 PHP 课
class SurveyQuestion extends CActiveRecord
{
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(
'surveyOptions' => array(self::HAS_MANY, 'SurveyOptions', 'surveyQuestion_id'),
'survey' => array(self::BELONGS_TO, 'Survey', 'survey_id'),
);
}
}
在控制器中,我想获得带有选项的调查列表,所以我正在做..
and in controller, I want to get list of surveys with its options, so I am doing..
$this->renderJson(array('success'=>true, 'message'=>'Records Retrieved Successfully',
'data'=>SurveyQuestion::model()->with('surveyOptions')->findAll()));
但是当这个控制器方法被调用时,我收到这个错误..
but when this controller method is getting called, I am getting this error..
include(SurveyOptions.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory
根据 http://www.yiiframework.com/doc/guide/1.1/en/database.arr,我应该能够在每个调查中得到带有选项的回复.
As per http://www.yiiframework.com/doc/guide/1.1/en/database.arr, I should be able to get response with options in each survey.
我认为,inclue(SurveyOptions.php) 应该是 SurveyOption.php(没有 's')但是我看不出有什么问题?
I think, inclue(SurveyOptions.php) should be SurveyOption.php (without 's') but I am not able to see what is wrong?
推荐答案
看完你的评论,你只需要改变你的关系:
After reading your comments, you just need to change your relation :
'surveyOptions' => array(self::HAS_MANY, 'SurveyOption', 'surveyQuestion_id')
因为你的类名是 SurveyOption
并且文件是 SurveyOption.php
Since your class name is SurveyOption
and file is SurveyOption.php
这篇关于Yii,使用 with() 方法调用时 findAll 出错.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!