Пример #1
0
 /** 
  * Create init user 
  */
 public function actionUser()
 {
     echo "创建一个新用户 ...\n";
     // 提示当前操作
     $username = $this->prompt('User Name:');
     // 接收用户名
     $email = $this->prompt('Email:');
     // 接收Email
     $password = $this->prompt('Password:');
     // 接收密码
     $model = new Admin();
     // 创建一个新用户
     $model->username = $username;
     // 完成赋值
     $model->email = $email;
     $model->password = $password;
     if (!$model->save()) {
         foreach ($model->getErrors() as $error) {
             foreach ($error as $e) {
                 echo "{$e}\n";
             }
         }
         return 1;
         // 命令行返回1表示有异常
     }
     return 0;
     // 返回0表示一切OK
 }
Пример #2
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === null) {
         $this->_user = Admin::findByUsername($this->username);
     }
     return $this->_user;
 }
Пример #3
0
 /**
  * 欢迎界面
  */
 public function actionWelcome()
 {
     //查询登陆用户
     $id = \Yii::$app->user->id;
     $admin = Admin::findOne($id)->attributes;
     return $this->render('welcome', ['admin' => $admin]);
 }