PHP项目开发框架,基于composer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
710 B

  1. <?php
  2. namespace Wiggins\MyProject\Example;
  3. require __DIR__.'/../vendor/autoload.php';
  4. require __DIR__.'/../vendor/yiisoft/yii2/Yii.php';
  5. use Wiggins\MyProject\UserInput;
  6. use Wiggins\MyProject\MyValidator;
  7. //创造一个模型对象
  8. $model=new UserInput(['scenario'=>'login']);
  9. $inputDate=[
  10. "name" => "kuangweijian",
  11. "password" => "123456546",
  12. ];
  13. $model->setAttributes($inputDate);
  14. //使用独立验证器
  15. $validator = new MyValidator();
  16. if($validator->validateAttribute($model, "name")){
  17. echo "login succ".PHP_EOL;
  18. }else{
  19. echo "login failed".PHP_EOL;
  20. print_r($model->getErrors());
  21. }
  22. ?>