/** 
  * Create init user 
  */
 public function actionAdmin()
 {
     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
 }
Beispiel #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;
 }