/** * Create init user */ public function actionAdmin() { echo "Create init agadmin ...\n"; // 提示当前操作 $username = $this->prompt('User Name:'); // 接收用户名 $email = $this->prompt('Email:'); // 接收Email $password = $this->prompt('Password:'); // 接收密码 $model = new AgAdmin(); // 创建一个新用户 $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 }
/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = AgAdmin::findByUsername($this->username); } return $this->_user; }