「Php/fuelphp/migration/model crud」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「==migrationを使ってmodelを作成する== php oil g model test name:varchar[50] created_at:datetime --crud *fuel/app/classes/model/test.php <?php class Model_Test...」) |
|||
(同じ利用者による、間の7版が非表示) | |||
行1: | 行1: | ||
− | == | + | ==migrationを使ってcrudのmodelを作成する== |
− | php oil g model | + | php oil g model user name:varchar[31] email:string[63] password:string[31] msg:text created_at:int updated_at:int --crud |
− | *fuel/app/classes/model/ | + | 以下2つのファイル(modelとmigration)ができる |
− | + | ||
− | + | *fuel/app/classes/model/user.php | |
− | + | class Model_User extends \Model_Crud | |
− | + | { | |
− | + | protected static $_properties = array( | |
− | + | 'id', | |
− | + | 'name', | |
− | + | 'email', | |
− | + | 'password', | |
− | + | 'msg', | |
− | + | 'created_at', | |
+ | 'updated_at', | ||
+ | ); | ||
+ | protected static $_table_name = 'users'; | ||
+ | } | ||
+ | |||
+ | *fuel/app/migrations/002_create_users.php | ||
+ | namespace Fuel\Migrations; | ||
+ | class Create_users | ||
+ | { | ||
+ | public function up() | ||
+ | { | ||
+ | \DBUtil::create_table('users', array( | ||
+ | 'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true, 'unsigned' => true), | ||
+ | 'name' => array('constraint' => 31, 'type' => 'varchar'), | ||
+ | 'email' => array('constraint' => 63, 'type' => 'varchar'), | ||
+ | 'password' => array('constraint' => 31, 'type' => 'varchar'), | ||
+ | 'msg' => array('type' => 'text'), | ||
+ | 'created_at' => array('type' => 'datetime'), | ||
+ | 'updated_at' => array('type' => 'datetime'), | ||
+ | ), array('id')); | ||
+ | } | ||
+ | public function down() | ||
+ | { | ||
+ | \DBUtil::drop_table('users'); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | *以下コマンド実行でmigrationが実行されtableができる | ||
+ | php oil refine migrate | ||
+ | |||
+ | *こんなテーブルができる | ||
+ | CREATE TABLE `users` ( | ||
+ | `id` int(11) unsigned NOT NULL AUTO_INCREMENT, | ||
+ | `name` varchar(31) NOT NULL, | ||
+ | `email` varchar(63) NOT NULL, | ||
+ | `password` varchar(31) NOT NULL, | ||
+ | `msg` text NOT NULL, | ||
+ | `created_at` int(11) NOT NULL, | ||
+ | `updated_at` int(11) NOT NULL, | ||
+ | PRIMARY KEY (`id`) | ||
+ | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; |
2015年10月25日 (日) 02:11時点における最新版
migrationを使ってcrudのmodelを作成する
php oil g model user name:varchar[31] email:string[63] password:string[31] msg:text created_at:int updated_at:int --crud
以下2つのファイル(modelとmigration)ができる
- fuel/app/classes/model/user.php
class Model_User extends \Model_Crud { protected static $_properties = array( 'id', 'name', 'email', 'password', 'msg', 'created_at', 'updated_at', ); protected static $_table_name = 'users'; }
- fuel/app/migrations/002_create_users.php
namespace Fuel\Migrations; class Create_users { public function up() { \DBUtil::create_table('users', array( 'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true, 'unsigned' => true), 'name' => array('constraint' => 31, 'type' => 'varchar'), 'email' => array('constraint' => 63, 'type' => 'varchar'), 'password' => array('constraint' => 31, 'type' => 'varchar'), 'msg' => array('type' => 'text'), 'created_at' => array('type' => 'datetime'), 'updated_at' => array('type' => 'datetime'), ), array('id')); } public function down() { \DBUtil::drop_table('users'); } }
- 以下コマンド実行でmigrationが実行されtableができる
php oil refine migrate
- こんなテーブルができる
CREATE TABLE `users` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(31) NOT NULL, `email` varchar(63) NOT NULL, `password` varchar(31) NOT NULL, `msg` text NOT NULL, `created_at` int(11) NOT NULL, `updated_at` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;