当前位置: 首页>>代码示例>>PHP>>正文


PHP Migration::upIndex方法代码示例

本文整理汇总了PHP中yii\db\Migration::upIndex方法的典型用法代码示例。如果您正苦于以下问题:PHP Migration::upIndex方法的具体用法?PHP Migration::upIndex怎么用?PHP Migration::upIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\db\Migration的用法示例。


在下文中一共展示了Migration::upIndex方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getMenu

 public function getMenu()
 {
     $gitignore = join(DIRECTORY_SEPARATOR, [\Yii::getAlias('@app'), '.gitignore']);
     $array = [["text" => "Copy .htaccess to @app/web", "checked" => true, "disabled" => function (ConsoleCheckBox $item) {
         $dir = [\Yii::getAlias('@app'), 'web', '.htaccess'];
         return file_exists(join(DIRECTORY_SEPARATOR, $dir));
     }, "exec" => function (ConsoleCheckBox $item) {
         $source = [\Yii::getAlias('@vendor'), 'carono', 'yii2-components', 'templates', '.htaccess'];
         $dist = [\Yii::getAlias('@app'), 'web', '.htaccess'];
         return copy(join(DIRECTORY_SEPARATOR, $source), join(DIRECTORY_SEPARATOR, $dist));
     }], ["text" => "Add db.php to @app/.gitignore", "checked" => true, "disabled" => function (ConsoleCheckBox $item) use($gitignore) {
         $lines = explode("\n", file_get_contents($gitignore));
         return array_search('db.php', $lines) || array_search('/config/db.php', $lines);
     }, "exec" => function (ConsoleCheckBox $item) use($gitignore) {
         file_put_contents($gitignore, "\n/config/db.php", FILE_APPEND);
         return true;
     }, "error" => !file_exists($gitignore)], ["text" => "Create currency table", "checked" => true, "disabled" => function (ConsoleCheckBox $item) {
         return (bool) Yii::$app->db->getTableSchema('currency');
     }, "exec" => self::migrate('@carono/migrations/m151216_093214_currency')], ["text" => "Create cities table", "id" => "cities", "checked" => true, "disabled" => (bool) Yii::$app->db->getTableSchema('city'), "exec" => self::migrate('@carono/migrations/m151216_084006_cities')], ["text" => "Create RBAC (@yii/rbac/migrations)", "checked" => true, "disabled" => function (ConsoleCheckBox $item) {
         return (bool) Yii::$app->db->getTableSchema('auth_item');
     }, "exec" => self::migrate('@yii/rbac/migrations')], ["text" => "Create 'file_upload' table", "checked" => true, "disabled" => (bool) Yii::$app->db->getTableSchema('file_upload'), "exec" => self::migrate('@carono/migrations/m151127_104851_file_upload_table')], ["text" => "Create 'company' table (RUS)", "checked" => true, "disabled" => (bool) Yii::$app->db->getTableSchema('company'), "exec" => self::migrate('@carono/migrations/m160222_202733_company')], ["text" => "Create 'User' table", "id" => "user", "checked" => true, "disabled" => (bool) Yii::$app->db->getTableSchema('user'), "exec" => function (ConsoleCheckBox $item) {
         $command = new Migration();
         $table = ['user' => ['id' => $command->primaryKey(), 'login' => $command->string(), 'hash' => $command->string(), 'activation_code' => $command->string(), 'recover_code' => $command->string(), 'last_logon' => $command->dateTime(), 'access_token' => $command->string(), 'created' => $command->dateTime(), 'updated' => $command->dateTime(), 'active' => $command->boolean()->notNull()->defaultValue(false)], 'address' => ['id' => $command->primaryKey(), 'raw' => $command->string(), 'postcode' => $command->string(), 'street' => $command->string(), 'build' => $command->string(), 'structure' => $command->string(), 'flat' => $command->string(), 'registration_date' => $command->date()]];
         if ($item->owner->findById('cities')->value) {
             $table["address"]["city_id"] = [$command->integer(), 'city', 'id'];
         }
         if ($item->findById('photos')->value) {
             $table["user"]["photos"] = [$command->pivot(), 'file_upload', 'id', 'photo_id'];
         }
         if ($item->findById('personal')->value) {
             $table["user"]["personal_id"] = [$command->integer(), 'personal', 'id'];
             $table["personal"] = ['id' => $command->primaryKey(), 'email' => $command->string(), 'first_name' => $command->string(), 'second_name' => $command->string(), 'patronymic' => $command->string(), 'birth_date' => $command->date(), 'sex' => $command->boolean(), 'phone' => $command->string(), 'avatar_id' => [$command->integer(), 'file_upload', 'id'], 'legal_address_id' => [$command->integer(), 'address', 'id'], 'real_address_id' => [$command->integer(), 'address', 'id'], 'updated' => $command->dateTime()];
         } else {
             $table["user"] = array_merge($table["user"], ['email' => $command->string(), 'first_name' => $command->string(), 'second_name' => $command->string(), 'patronymic' => $command->string(), 'birth_date' => $command->date(), 'sex' => $command->boolean(), 'phone' => $command->string(), 'legal_address_id' => [$command->integer(), 'address', 'id'], 'real_address_id' => [$command->integer(), 'address', 'id']]);
         }
         $index = [["user", "login", true], ["user", "access_token", true]];
         $command->upTables($table);
         $command->upFk($command->collectFks($table));
         $command->upIndex($index);
         return true;
     }, "items" => [["id" => "personal", "text" => "User profile as relation", "checked" => true, "inherit" => true], ["id" => "photos", "text" => "Create with photos", "checked" => true, "inherit" => true], ["id" => "user_model", "text" => "Copy default User model", "checked" => false, "exec" => function () {
         $source = [\Yii::getAlias('@vendor'), 'carono', 'yii2-components', 'templates', 'User.php'];
         $dist = [\Yii::getAlias('@app'), 'models', 'User.php'];
         return copy(join(DIRECTORY_SEPARATOR, $source), join(DIRECTORY_SEPARATOR, $dist));
     }]]]];
     return $array;
 }
开发者ID:carono,项目名称:yii2-installer,代码行数:47,代码来源:MainController.php


注:本文中的yii\db\Migration::upIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。