Browse Source

修改注释

master
kuangweijian 3 years ago
parent
commit
45bab13db1
  1. 8
      examples/user-login.php
  2. 8
      examples/user-register.php
  3. 34
      src/UserInput.php

8
examples/user-login.php

@ -2,21 +2,23 @@
namespace Wiggins\MyProject\Example;
require __DIR__.'/../vendor/autoload.php';
require __DIR__.'/../vendor/yiisoft/yii2/Yii.php';
use Wiggins\MyProject\UserInput;
use Wiggins\MyProject\Models\UserInput;
/*创建登陆场景的对象*/
$model=new UserInput(['scenario'=>'login']);
/*创建数组,用load()加载属性*/
$inputDate=[
"name" => "kuangweijian",
"password" => "123456546",
];
$model->load($inputDate,'');
/*判断属性是否符合规则*/
if($model->validate()){
echo "login succ".PHP_EOL;
}else{
echo "login failed".PHP_EOL;
print_r($model->getErrors());
}
?>
?>

8
examples/user-register.php

@ -2,11 +2,12 @@
namespace Wiggins\MyProject\Example;
require __DIR__.'/../vendor/autoload.php';
require __DIR__.'/../vendor/yiisoft/yii2/Yii.php';
use Wiggins\MyProject\UserInput;
use Wiggins\MyProject\Models\UserInput;
/*创建注册场景的对象*/
$model=new UserInput(['scenario'=>'register']);
/*创建数组,用load()加载属性*/
$inputDate=[
"name" => "kuangweiian",
"email" => "12345678@qq.com",
@ -15,10 +16,11 @@
];
$model->load($inputDate,'');
/*判断属性是否符合规则*/
if($model->validate()){
echo "register succ".PHP_EOL;
}else{
echo "register failed".PHP_EOL;
print_r($model->getErrors());
}
?>
?>

34
src/UserInput.php

@ -1,26 +1,24 @@
<?php
namespace Wiggins\MyProject;
namespace Wiggins\MyProject\Models;
use yii\base\Model;
/**
* 说明:用户注册或登录场景模型
* 属性:
* @name string 用户名
* @eamil string 用户邮箱
* @password string 用户密码
* @pwdConfirm string 确认密码
*/
class UserInput extends Model
{
/**
public $name; //@var string 姓名
public $email; //@var string 邮箱
public $password; //@var string 密码
public $pwdConfirm; //@var string 确认密码
/**
* @scenario 登陆场景
*/
public $name;
public $email;
public $password;
public $pwdConfirm;
const SCENARIO_LOGIN = 'login';
/**
* @scenario 注册场景
*/
const SCENARIO_REGISTER = 'register';
public function attributeLabels()
@ -36,8 +34,8 @@
public function scenarios()
{
return[
'login' => ['name','password'],
'register' => ['name','email','password','pwdConfirm'],
self::SCENARIO_LOGIN => ['name','password'],
self::SCENARIO_REGISTER => ['name','email','password','pwdConfirm'],
];
}
@ -61,4 +59,4 @@
];
}
}
?>
?>
Loading…
Cancel
Save