小日日

Stay hungry,stay foolish

0%

Hyperf常用命令

路由

自动注解路由

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/

namespace App\Controller\Api\v1;

use App\Controller\AbstractController;
use App\Model\Wallpaper;
use Hyperf\HttpServer\Response;
use Psr\Http\Message\ResponseInterface;
use Hyperf\HttpServer\Annotation\AutoController; //1.引入注解命名空间

/**
* @AutoController() //2.声明自动控制器路由 路由地址 /api/v1/index/方法名
*/
class IndexController extends AbstractController
{

/**
* 首页接口
* @param Response $response
* @return ResponseInterface
*/
public function page(Response $response): ResponseInterface
{
$step = (int)$this->request->input('step', 20);
$data = Wallpaper::paginate($step);
$response->withHeader('Access-Control-Allow-Origin', '*')
->withHeader('Access-Control-Allow-Credentials', 'true')
->withHeader('Access-Control-Allow-Headers', '*');
return $response->json(['data' => $data, 'code' => 0, 'msg' => '666']);
}
}

中间件

生成中间件

1
php bin/hyperf.php gen:middleware CorsMiddleware

创建模型

1
php bin/hyperf.php gen:model cash_record

创建验证器

1
php bin/hyperf.php gen:request FooRequest

创建资源集合

1
php bin/hyperf.php gen:resource User

创建数据库迁移

1
php bin/hyperf.php gen:migration create_cash_record_table --create=cash_record

运行迁移

1
php bin/hyperf.php migrate

创建控制器

1
php bin/hyperf.php gen:controller admin/InvestmentSummaryRecord

创建命令行

1
php bin/hyperf.php gen:command SettlementCommand