public function beforeAction($action) { if (!$this->isLogin()) { $this->layout = false; return $this->redirect("/admin/login"); //用户未登录自动跳转至登录页 } $user = new User(); $user->setUser(\Yii::$app->session->get(USER_SESSION)); \Yii::$app->view->params['user'] = $user->getUser(); // 当前用户 $this->user = $user; $this->isCan(); //权限验证 $this->assign('currentUserRole', $user->getUser()['role']); $this->assign('currentUserId', $user->getUser()['id']); return parent::beforeAction($action); // TODO: Change the autogenerated stub }
public function beforeSave($insert) { if (parent::beforeSave($insert)) { if ($this->isNewRecord) { } else { } // $this->_oldTag = $this->tag; $this->user_by = \Yii::$app->user->identity->nama_depan; $this->schedule_date = date('Y-m-d H:i:s', strtotime(str_replace("-", "", $this->schedule_date))); isset($this->author) ? $this->author_name = User::getUser($this->author)->nama_depan : ($this->author_name = NUll); isset($this->categori_id) ? $this->categori_name = Category::getCateory($this->categori_id)->nama : ($this->categori_name = NUll); return true; } else { return false; } }