/** * Creates a new AdminUser model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new AdminUser(); if ($model->load(Yii::$app->request->post())) { if ($model->save() && $model->accessRole($model->id, $model->role)) { return $this->redirect(['index']); } } else { return $this->render('create', ['model' => $model]); } }
public function actionDoadd() { $adminuser = new AdminUser(); $adminuser->username = $_POST['username']; $adminuser->password = md5($_POST['password']); if ($adminuser->save()) { echo $this->success("添加成功", "index.php?r=user", '1'); } else { echo $this->error("添加失败", "index.php?r=user", '1'); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $username = Input::get('username', null); $password = Input::get('password', null); if ($username and $password) { if (!AdminUser::where(['username' => $username])->first()) { $user = new AdminUser(); $user->username = $username; $user->password = sha1($password); $user->coupon_id = Input::get('coupon', 0); if ($user->save()) { return redirect('admin/users/show'); } } } return redirect()->back(); }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param ConnectionInterface $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(ConnectionInterface $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their corresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aAdminCredential !== null) { if ($this->aAdminCredential->isModified() || $this->aAdminCredential->isNew()) { $affectedRows += $this->aAdminCredential->save($con); } $this->setAdminCredential($this->aAdminCredential); } if ($this->aAdminUser !== null) { if ($this->aAdminUser->isModified() || $this->aAdminUser->isNew()) { $affectedRows += $this->aAdminUser->save($con); } $this->setAdminUser($this->aAdminUser); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); $affectedRows += 1; } else { $affectedRows += $this->doUpdate($con); } $this->resetModified(); } $this->alreadyInSave = false; } return $affectedRows; }