我正在使用cakephp开发一个Web应用程序。我有一个函数,我想使用cakephp的save()方法将一些数据保存到模型中。但每当我要保存数据时,我都会遇到这种错误:
Fatal error: Call to undefined method App::save() in /httpdocs/MyApp/app/Controller/AppsController.php on line 71
任何人都知道我在这里缺少什么。我的控制器功能如下:
public function add_app($id=null){
$this->layout = 'user';
if (!empty($id)) {
$this->request->data['App']['id_users'] = $_SESSION['edit_user_id'];
$this->request->data['App']['id_store'] = $id;
$this->request->data['App']['id_unique_app'] = $Guid;
$this->request->data['App']['tx_app_name'] = $data['results'][0]['trackName'];
$this->request->data['App']['tx_platform'] = 'iOS';
$this->request->data['App']['nu_price'] = $data['results'][0]['price'];
$this->request->data['App']['da_created'] = date("Y-m-d H:i:s");
if ($this->App->save($this->request->data)) {
$this->Session->setFlash('The selected app has been added successfully.');
$this->redirect(array('action' => 'index'));
}
}
}
提前感谢。
答案 0 :(得分:0)
尝试
if ($this->save($this->request->data))
而不是
if ($this->App->save($this->request->data))
答案 1 :(得分:0)
你的控制器名称是什么?
在CakePHP中,“App”控制器只能调用“App”模型。
如果它是“App”控制器,那么你必须使用
if ($this->save($this->request->data))
而不是
if ($this->App->save($this->request->data))
答案 2 :(得分:0)
您可以在控制器类的顶部使用$uses = array('ModelName');
。
然后你可以使用:
$this->ModelName->save($this->request->data);