cake migration

// making migration 
[vagrant@localhost myblog]$ bin/cake bake migration_snapshot Initial

[vagrant@localhost myblog]$ bin/cake migrations status
using migration paths
 - /home/vagrant/fw/myblog/config/Migrations
using seed paths
 - /home/vagrant/fw/myblog/config/Seeds
using environment default

 Status  Migration ID    Migration Name
-----------------------------------------
     up  20180306042845  Initial


[vagrant@localhost myblog]$ bin/cake bake migration CreateComments post_id:integer body:string created modified

Creating file /home/vagrant/fw/myblog/config/Migrations/20180306043056_CreateComments.php
Wrote `/home/vagrant/fw/myblog/config/Migrations/20180306043056_CreateComments.php

[vagrant@localhost myblog]$ bin/cake migrations migrate
`

mysqlで確認

mysql> use cake
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------+
| Tables_in_cake |
+----------------+
| comments       |
| phinxlog       |
| posts          |
+----------------+
3 rows in set (0.00 sec)

すげー

commentController

<?php

namespace App\Controller;

class CommentsController extends AppController
{
	public function  add()
	{
		$this->viewBuilder()->layout('my_layout');
		$comment = $this->Comments->newEntity();
		if($this->request->is('post')){
			$comment = $this->Comments->patchEntity($comment, $this->request->data);
			if($this->Comments->save($comment)){
				$this->Flash->success('Comment Add Success!');
				return $this->redirect(['controller'=>'Posts','action'=>'view', $comment->post_id]);
			}else {
				$this->Flash->success('Error');
			}
		}
		$this->set('post', $comment);
	}

	public function delete($id = null)
	{
		$this->viewBuilder()->layout('my_layout');
		$this->request->allowMethod(['post', 'delete']);
		$comment = $this->Comments->get($id);
		if($this->Comments->delete($comment)){
			$this->Flash->success('Comment Delete Success!');
			
		}else {
			$this->Flash->success('Error');
		}
		return $this->redirect(['controller'=>'Posts','action'=>'view', $comment->post_id]);

	}
}
?>