bobysky
登录的代码
app\models\loginform
public function login() { if ($this->validate()) { return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600*24*30 : 0); } else { return false; } } public function getUser() { if ($this->_user === false) { $this->_user = User::findByUsername($this->username); } return $this->_user; }
app\models\user
class User extends ActiveRecord implements \yii\web\IdentityInterface { public $rememberMe; public $username; public $password; public static function tableName() { return '{{%user}}'; } public static function findIdentity($id){ return static::findOne($id); } /** * @inheritdoc */ public static function findIdentityByAccessToken($token, $type = null) { return static::findOne(['access_token' => $token]); } /** * Finds user by username * * @param string $username * @return static|null */ public static function findByUsername($username) { $user = User::find() ->where(['UserName' => $username]) ->asArray() ->one(); if($user){ return new static($user); } return null; } /** * @inheritdoc */ public function getId() { return $this->UserName; } /** * @inheritdoc */ public function getAuthKey() { return $this->authKey; } /** * @inheritdoc */ public function validateAuthKey($authKey) { return $this->authKey === $authKey; } /** * Validates password * * @param string $password password to validate * @return boolean if password provided is valid for current user */ public function validatePassword($password) { if($password===$password){ return true; }else{ return false; } } public function test(){ $user=user::findOne(['username'=>'3color']); var_dump($user); } }
- bobysky 评论了源码 Yii2.0 通用后台系统
飞哥,我执行php -S localhost:8000后, CLI停止工作,是什么原因?我的php版本5.4.3