2012-04-03 21 views
1

嘗試保存時出現以下錯誤。多選錯誤

SQL Query: INSERT INTO `table`.`users` (`username`, `password`, `group_id`, `applications`, `modified`, `created`) VALUES ('asdasd', '23ad37a839e26fc46a1f6640861a47305aea5d46', 3, Array, '2012-04-03 02:12:19', '2012-04-03 02:12:19') 

這裏是多個代碼選擇

echo $this->Form->input('User.applications',array('options'=>$options,'multiple'=>'multiple')); 

和add方法被調用,它是:

if ($this->request->is('post')) { 
           //debug($this->request);exit; 
           $this->User->create(); 
           if ($this->User->saveAll($this->request->data)) { 
            $this->Session->setFlash(__('The user has been saved')); 
            $this->redirect(array('action' => 'index')); 
           } else { 
            $this->Session->setFlash(__('The user could not be saved. Please, try again.')); 
           } 
          } 
          $groups = $this->User->Group->find('list'); 
          $this->set(compact('groups')); 

的感謝!

回答

0

解決它使用該

public function add() { 
          if ($this->request->is('post')) { 

           if(count($this->request->data['User']['applications'])){ 
            $this->request->data['User']['applications'] = implode(",", $this->request->data['User']['applications']); 
           } 
       .... 
+0

這樣的作品,但請記住,這將是很難進行搜索或加入該列。理想情況下,您應該使用單獨的表格和模型來管理每個用戶的多個應用程序。 – bfavaretto 2012-04-03 03:48:25