表单是在CakePHP中提交数组而不是想要的字段

时间:2014-11-16 00:02:27

标签: php mysql cakephp cakephp-2.0

我是新蛋糕,我正在努力学习它的哲学。所以我想创建一个表格&#34;电影&#34;如下所示,我的数据库接受movie_id,标题,年份和描述。当我运行代码时,它会尝试存储&#34;数组&#34;作为年份输入。这是我得到的错误=&gt; movie_idtitleyeardescription)VALUES(NULL,&#39; Movie1&#39;,数组,&#39;某些文字&#39;)< / p>

观点:

   <?php echo $this->Form->create('Movie'); ?>
    <?php echo __('Add Movie'); ?>

     <?php
        echo $this->Form->hidden('movie_id');

        echo $this->Form->input('title');

         echo $this->Form->input('year', array(
            'type'=>'date',
            'dateFormat'=>'Y',
            'minYear'=>'1990',
            'maxYear'=>date('Y'),
        ));

        echo $this->Form->input('description');

        ?>

<?php echo $this->Form->end(__('Submit')); 

?>

控制器:

public function add() {

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

    $this->Movie->create();

      if ($this->Movie->save($this->request->data)) {
        $this->Session->setFlash(__('The movie has been created'));
        $this->redirect (array('action'=>'index'));
      } 

      else {

        $this->Session->setFlash(__('The movie could not be created. Please, try again.'));

      }
}
}

正如我所说,我是新蛋糕,所以如果这个问题听起来很愚蠢我会道歉,请给出你的解决方案。感谢

0 个答案:

没有答案