1. Go to this page and download the library: Download yjyer/php-dto 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/ */
yjyer / php-dto example snippets
declare(strict_types=1);
namespace app\account\dto;
use yjyer\phpdto\attribute\{IsDto, Validate, Field};
/**
* 验证类
*/
#[IsDto(dto: 1)]
class UserDto
{
#[Validate(v: '��要输入太多或太小啊')]
#[Field(title: "年龄", default: "")]
public int $age;
#[Validate(v: 'number|between:1,100')]
#[Field(title: "位置", default: "1")]
public int $position;
#[Validate(v: 'email|
declare(strict_types=1);
namespace app\account\controller;
use app\account\dto\UserDto;
use yjyer\phpdto\attribute\ParamDto;
class Index
{
/**
*
* 用户信息方法
*
*/
#[ParamDto(field: "age", title: "年龄", default: "18", v: 'number|between:1,120')]
public function user(UserDto $userDto)
{
//1、输出已经注入UserDto内的参数
//2、这里能拿到的数据,都是通过了验证的数据
//3、如果ParamDto里有和Dto类(如UserDto)类里相同的字段,则优先使用ParamDto的配置
dd($userDto);
return '您好!这是一个[account]示例应用,请参考';
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.