函數我有教師平均速度的函數,我保存變量的平均值$result
我想將變量傳遞給get_teacher_average_rating
並打印平均值,但我嘗試這樣做,我有錯誤通過函數cakephp 2
通知(8):未定義變量:導致 [APP /控制器/ RatingSchoolsController.php 30行]警告(2): 無法修改標題信息 - 頭已經發出(輸出 開始在 /應用/MAMP/htdocs/classera-core-code/lib/Cake/Utility/Debugger.php:795) [APP/Controller/AppController.php,li NE 67]
我怎麼能解決這個問題,並打印平均get_teacher_average_rating
public function set_teacher_average_rating($result)
{
$this->autoRender = false;
if($this->request->is('get'))
{
$author_id = $this->request->query('author_id');//
$rate = $this->Rating->find('all',array('conditions'=>array('author_id'=> $author_id), 'fields'=> array('AVG(Rating.value) as averageRating'), 'recursive' =>-1));
$average = $rate[0][0]['averageRating'];
$result = array('success'=>'1' , 'average' => $average);
}
else{
$result = array('success'=>'0','message'=>'request type is not GET');
}
echo json_encode($result);
}
public function get_teacher_average_rating()
{
$this->autoRender = false;
$average = $this->set_teacher_average_rating($result);
$rate = $this->Rating->find('all',array('conditions'=>array('author_id'=> $author_id)));
//get rate teacher
echo json_encode($average);
}
'$ average = $ this-> get_teacher_average_rating($ result);'__What__是'$ result'在這裏? –
$ result在get_teacher_average_rating中來自哪裏?從視圖?會話? –
那麼'get_teacher_average_rating'調用'get_teacher_average_rating'?你確定你做對了嗎? –