0
在我正在開發的應用程序,我創建了一個形式view.ctp文件:如何解決 - 調用成員函數save()在蛋糕php中的非對象?
<?php
echo $form->create('Answer',array('action'=>'addanswer'));
echo $form->input('ques',array('value'=>'1'));
$userInfo=$this->Session->read('Auth.User');
$user=$userInfo['id'];
echo $form->input('user',array('value'=>$user));
echo $form->input('answer');
echo $form->end('Submit answer');
?>
而在answers_controllers.php文件,我有以下代碼:
<?php
class AnswersController extends AppController{
var $name= 'Answers';
var $uses = array('User');
function addanswer(){
if(!empty ($this->data)){
echo $this->data;
if($this->Answer->save($this->data)){
$this->Session->setFlash('The answer has been addedd successfully');
$this->redirect(array('action'=>'index'));
}
else{
$this->Session->setFlash('The answer was not saved. Please re enter the details');
}
}
$this->set('title_for_layout','Add a new Answer');
}
}
?>
但當我按提交答案按鈕(在view.ctp中提到)時,我得到一個非對象的成員函數save()的調用。 一個非常類似於這個代碼的代碼可以很好地工作,但這不起作用。
我是新來的蛋糕PHP,所以任何關於如何解決這個問題的幫助將不勝感激。
非常感謝您提前。