Note that there are some explanatory texts on larger screens.

plurals
  1. POThe add method in a CakePHP Controller doesn't work
    primarykey
    data
    text
    <p>When I am trying to include new content, in this controller, he's not running the save option and returns the error message, since I used the print_r function to check the $ this-> request-> data, and is passing the correct parameters. below is the code:</p> <p>Controller/CanvasController.php:</p> <pre><code>class CanvasController extends AppController { public $name = 'Canvas'; function beforeFilter() { parent::beforeFilter(); //$this -&gt; layout = 'dialog'; $this -&gt; layout = 'default-original'; } public function index() { $this -&gt; set('Canvas', $this -&gt; Canvas -&gt; find('all')); } public function add() { if ($this -&gt; request -&gt; is('post')) { if ($this -&gt; Canvas -&gt; save($this -&gt; request -&gt; data)) { $this -&gt; Session -&gt; setFlash(__('The Canvas has been saved')); $this -&gt; redirect(array('action' =&gt; 'index')); } else { $this -&gt; Session -&gt; setFlash(__('The Canvas could not be saved. Please, try again.')); } } } public function edit($id = null) { $this -&gt; Canvas -&gt; id = $id; if ($this -&gt; request -&gt; is('get')) { $this -&gt; request -&gt; data = $this -&gt; Canvas -&gt; read(); } else if ($this -&gt; Canvas -&gt; save($this -&gt; request -&gt; data)) { $this -&gt; Session -&gt; setFlash('Canvas updated.'); $this -&gt; redirect(array('controller' =&gt; 'user', 'action' =&gt; 'index')); } } public function delete($id = null) { if (!$this -&gt; request -&gt; is('post')) { throw new MethodNotAllowedException(); } $this -&gt; Canvas -&gt; id = $id; if (!$this -&gt; Canvas -&gt; exists()) { throw new NotFoundException(__('Invalid.')); } if ($this -&gt; Canvas -&gt; delete($id)) { $this -&gt; Session -&gt; setFlash('The Canvas with id: ' . $id . ' has been deleted.'); $this -&gt; redirect(array('controller' =&gt; 'user', 'action' =&gt; 'index')); } $this -&gt; Session -&gt; setFlash(__('Canvas was deleted.')); $this -&gt; redirect(array('controller' =&gt; 'user', 'action' =&gt; 'index')); } } </code></pre> <p>Model/Canvas.php:</p> <pre><code>class Canvas extends AppModel { public $name = 'Canvas'; public $hasAndBelongsToMany = array( 'users' =&gt; array( 'classname' =&gt; 'Users', 'foreignkey' =&gt; 'canvas_id', 'joinTable' =&gt; 'canvas_has_users' ) ); public $hasMany = array( 'CanvasContents' =&gt; array( 'classname' =&gt; 'CanvasContents', 'foreignKey' =&gt; 'canvas_id' ) ); public $validate = array( 'name' =&gt; array( 'required' =&gt; array( 'rule' =&gt; array( 'notEmpty' ), 'message' =&gt; 'A name is required' ) ) ); } </code></pre> <p>View/Canvas/add.ctp:</p> <pre><code>&lt;?php echo $this -&gt; Form -&gt; create('Canvas'); ?&gt; &lt;fieldset&gt; &lt;?php echo $this -&gt; Form -&gt; input('name'); ?&gt; &lt;?php echo $this -&gt; Form -&gt; input('description'); ?&gt; &lt;/fieldset&gt; &lt;?php echo $this -&gt; Form -&gt; end('Submit');?&gt; </code></pre> <p>SQL code:</p> <pre><code>CREATE TABLE IF NOT EXISTS `sistema`.`canvas` ( `id` INT NOT NULL AUTO_INCREMENT, `name` VARCHAR(45) NOT NULL, `description` TEXT NULL, PRIMARY KEY (`id`)) ENGINE = InnoDB </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload