thinkphp5 摘要

in Inbox with 0 comment

1.配置

强制路由
conifg / app.php 文件中: 'url_route_must' => true

开启调式模式
config / app.php 文件中: 'app_debug' => true

2.路由 Route

route / route.php 文件
Route::rule(地址, 代码);

url地址 执行函数
Route::rule('/aaa', function(){ echo 'i love you'; });

url地址 执行类方法
Route::rule('/bbb', 'index/TestController/xxoo');

3.命令行

快速生成模块
php think build --module admin

快速生成控制器
php think make:controller admin/Users
php think make:controller admin/User --plain

快速生成模型
php think make:model User

4.migration

composer require topthink/think-migration
php think migrate:create Users

1.修改change方法

    public function change()
    {
        // create the table
        $table = $this->table('users');
        $table->addColumn('nickname', 'string', ['limit' => 16, 'null' => false])
              ->addColumn('email', 'string', ['limit' => 32, 'null' => false])
              ->addColumn('password', 'string', ['limit' => 64, 'null' => false])
              ->create();
    }

2.run

php think migrate:run

3.rollback

php think migrate:rollback

4.status

php think migrate:status

5.Seeder

php think seed:create UserSeeder
php think seed:run

public function run()
 {
      $rows = [];
      for ($i = 0; $i < 100; $i++) {
          $rows[] = [
              'nickname' => mt_rand(10000, 99999),
              'email' => mt_rand(10000, 99999).'@qq.com',
              'password' => md5('123456'),
          ];
      }
      $this->table('users')->insert($rows)->save();
}

6.Faker

composer require fzaninotto/faker

public function run()
{
    $faker = Faker\Factory::create();

    $rows = [];
    for ($i = 0; $i < 100; $i++) {
        $rows[] = [
        'nickname' => $faker->name,
        'email' => $faker->email,
        'password' => md5('123456'),
        ];
    }

    $this->table('users')->insert($rows)->save();
}