|
|
@ -1,25 +0,0 @@ |
|
|
|
<?php |
|
|
|
namespace Wiggins\MyProject\Example; |
|
|
|
require __DIR__.'/../vendor/autoload.php'; |
|
|
|
require __DIR__.'/../vendor/yiisoft/yii2/Yii.php'; |
|
|
|
|
|
|
|
use Wiggins\MyProject\UserInput; |
|
|
|
use Wiggins\MyProject\MyValidator; |
|
|
|
|
|
|
|
//创造一个模型对象
|
|
|
|
$model=new UserInput(['scenario'=>'login']); |
|
|
|
$inputDate=[ |
|
|
|
"name" => "kuangweijian", |
|
|
|
"password" => "123456546", |
|
|
|
]; |
|
|
|
$model->setAttributes($inputDate); |
|
|
|
|
|
|
|
//使用独立验证器
|
|
|
|
$validator = new MyValidator(); |
|
|
|
if($validator->validateAttribute($model, "name")){ |
|
|
|
echo "login succ".PHP_EOL; |
|
|
|
}else{ |
|
|
|
echo "login failed".PHP_EOL; |
|
|
|
print_r($model->getErrors()); |
|
|
|
} |
|
|
|
?>
|