多选时出错

时间:2012-04-03 02:16:12

标签: cakephp cakephp-2.0

尝试保存时出现以下错误。

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'));

谢谢!

1 个答案:

答案 0 :(得分: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']);
                                }
                ....