2012-07-02 47 views
0

我正在使用cakephp開發一個Web應用程序。我有一個函數,我想使用cakephp的save()方法將一些數據保存到模型中。但每當我要保存數據,我得到這種錯誤:在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

嘗試

if ($this->save($this->request->data)) 

代替

if ($this->App->save($this->request->data)) 
+0

@rikesh ..這是可能保存數據而不指定型號? –

+0

@amit - 我希望凱文向你解釋了同樣的情況:) – Rikesh

0

什麼是你的控制器名稱?

在CakePHP中,「App」控制器只能調用「App」模型。

,如果它的「應用程序」控制器,那麼你必須使用

if ($this->save($this->request->data)) 

代替

if ($this->App->save($this->request->data)) 
0

你可以在你的控制器類的頂部使用$uses = array('ModelName');

然後你可以使用:

$this->ModelName->save($this->request->data); 
相關問題