Php Yii迁移扩展自定义类
Php Yii迁移扩展自定义类,php,yii,migration,Php,Yii,Migration,cdbmiglation是要扩展的默认类我需要扩展自定义类customcdbmiglation 怎么做?配置中的一些设置?创建用于迁移的自定义类 class m150602_071107_naujassss extends CDbMigration { public function up() { } public function down() { echo "m150602_071107_tests does not support
cdbmiglation
是要扩展的默认类我需要扩展自定义类customcdbmiglation
怎么做?配置中的一些设置?创建用于迁移的自定义类
class m150602_071107_naujassss extends CDbMigration
{
public function up()
{
}
public function down()
{
echo "m150602_071107_tests does not support migration down.\n";
return false;
}
/*
// Use safeUp/safeDown to do migration with transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}
转到控制台,路径为受保护,执行命令“yiic migrate create test”。
转到生成的迁移文件并更改为:
/protected/components or /protected/extension/db (as you wish)
class CustomMigration extends CDbMigration
{
protected function getMyVar()
{
return 'Custom migration';
}
}
测试。在控制台“yiic migrate”中运行
class m150602_071449_test extends CustomMigration
{
public function up()
{
echo $this->getMyVar();
die();
}
...
是否应用上述迁移?(是|否)[否]:是
***应用m150602_071449_测试
自定义迁移数组(/*…*/),
“commandMap”=>数组(
“迁移”=>数组(
'class'=>'system.cli.commands.MigrateCommand',
“migrationPath'=>“application.migrations”,
'migrationTable'=>'tbl_migration',
'connectionID'=>'db',
'templateFile'=>'application.migrations.template',
),
),
//迁移模板/protected/migrations/template.php
好的,但我需要在我执行migrate create name
时将CustomMigration添加到migration created file auto中,我知道我们可以使用templateFile进行迁移。这是最好的办法。但我从来没用过这个。我更新了答案。您可以检查新版本。希望这对你有帮助。
Apply the above migration? (yes|no) [no]:yes
*** applying m150602_071449_test
Custom migration <------- my function
//console config
'components'=>array(/*...*/),
'commandMap'=>array(
'migrate'=>array(
'class'=>'system.cli.commands.MigrateCommand',
'migrationPath'=>'application.migrations',
'migrationTable'=>'tbl_migration',
'connectionID'=>'db',
'templateFile'=>'application.migrations.template',
),
),
//template for migrations /protected/migrations/template.php
<?php
class {ClassName} extends CustomMigration
{
public function up()
{
}
//other methods...
}