Form is submitting the Array instead of the wanted field in CakePHP

落花浮王杯 提交于 2019-12-13 03:35:42

问题


I am new to cake and I am trying to learn its philosophy. So I am trying to create a form "Movie" as follows and my database accepts movie_id, title, year, and description. When I run the code it tries to store the "array" as the year input. This is the error I get => movie_id, title, year, description) VALUES (NULL, 'Movie1', Array, 'some text')

THE VIEW:

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

?>

THE CONTROLLER:

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

      }
}
}

As I said I am new to cake so my apologies if this question sounds stupid, please give your solution. Thanks

来源:https://stackoverflow.com/questions/26952233/form-is-submitting-the-array-instead-of-the-wanted-field-in-cakephp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!