1. Go to this page and download the library: Download hollisho/webman-request library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hollisho / webman-request example snippets
namespace app\request;
use Hollisho\WebmanRequest\WebmanRequest;
class MyRequest extends WebmanRequest
{
// 定义请求参数属性
public $id;
public $status = 0; // 可以设置默认值
// 定义验证规则
public function rules()
{
return [
'id' => 's.number' => 'status必须为数字',
];
}
}
namespace app\controller;
use app\request\MyRequest;
use support\Response;
class IndexController
{
public function index(MyRequest $request)
{
// 验证通过后,可以直接使用请求对象的属性
$id = $request->id;
$status = $request->status;
// 业务逻辑处理...
return json(['code' => 0, 'msg' => 'success', 'data' => [
'id' => $id,
'status' => $status
]]);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.