m160716_091753_create_nav_table.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. use yii\db\Migration;
  3. /**
  4. * Handles the creation for table `{{%nav}}`.
  5. */
  6. class m160716_091753_create_nav_table extends Migration
  7. {
  8. /**
  9. * @inheritdoc
  10. */
  11. public function safeUp()
  12. {
  13. $tableOptions = null;
  14. if ($this->db->driverName === 'mysql') {
  15. $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
  16. }
  17. $this->createTable('{{%nav}}', [
  18. 'id' => $this->primaryKey(),
  19. 'key' => $this->string(128),
  20. 'title' => $this->string(128)
  21. ], $tableOptions);
  22. $this->createTable('{{%nav_item}}', [
  23. 'id' => $this->primaryKey(),
  24. 'nav_id' => $this->integer(11),
  25. 'title' => $this->string(128),
  26. 'url' => $this->string(128),
  27. 'target' => $this->smallInteger(1)->comment('是否新窗口打开')->defaultValue(0),
  28. 'order' => $this->smallInteger(1),
  29. 'status' => $this->smallInteger(1)->notNull()->defaultValue(0)
  30. ], $tableOptions);
  31. $this->insert('{{%nav}}', [
  32. 'id' => 1,
  33. 'key' => 'header',
  34. 'title' => '顶部导航'
  35. ]);
  36. $this->insert('{{%nav_item}}', [
  37. 'id' => 1,
  38. 'nav_id' => 1,
  39. 'title' => '首页',
  40. 'url' => '/',
  41. 'order' => 1,
  42. 'status' => 1
  43. ]);
  44. $this->insert('{{%nav_item}}', [
  45. 'id' => 2,
  46. 'nav_id' => 1,
  47. 'title' => '签到',
  48. 'url' => '/sign/index',
  49. 'order' => 2,
  50. 'status' => 1
  51. ]);
  52. $this->insert('{{%nav}}', [
  53. 'id' => 2,
  54. 'key' => 'friend-link',
  55. 'title' => '友情链接'
  56. ]);
  57. }
  58. /**
  59. * @inheritdoc
  60. */
  61. public function down()
  62. {
  63. $this->dropTable('{{%nav}}');
  64. $this->dropTable('{{%nav_item}}');
  65. }
  66. }