本文整理汇总了PHP中yii\base\Module::beforeAction方法的典型用法代码示例。如果您正苦于以下问题:PHP Module::beforeAction方法的具体用法?PHP Module::beforeAction怎么用?PHP Module::beforeAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\base\Module
的用法示例。
在下文中一共展示了Module::beforeAction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeAction
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
// Запретим доступ неавторизованным пользователям
// TODO убрать запрет и сделать нормальные поведения
if (Yii::$app->getUser()->isGuest) {
throw new ForbiddenHttpException('У вас нет прав просматривать данную страницу.');
}
if (isset($action->controller->breadcrumbItems)) {
$action->controller->addBreadcrumbsItem(['label' => 'Личный кабинет', 'url' => ['/cabinet']]);
$items = $action->controller->breadcrumbItems[$action->id];
if ($items === 'not add') {
// Просто выходим и разрешаем выолнять Action
return true;
}
if (is_array($items)) {
foreach ($items as $item) {
if (isset($item['url'])) {
$action->controller->addBreadcrumbsItem(['label' => $item['label'], 'url' => $item['url']]);
} else {
$action->controller->addBreadcrumbsItem(['label' => $item['label']]);
}
}
} else {
$action->controller->addBreadcrumbsItem(['label' => $items]);
}
} else {
$action->controller->addBreadcrumbsItem(['label' => 'Личный кабинет']);
}
return true;
// or false if needed
} else {
return false;
}
}
示例2: beforeAction
public function beforeAction($action)
{
if ($this->beforeAction !== null && !call_user_func($this->beforeAction, $action)) {
return false;
}
return parent::beforeAction($action);
}
示例3: beforeAction
/**
* @inheritdoc
*/
public function beforeAction($action)
{
if (!parent::beforeAction($action)) {
return false;
}
return true;
}
示例4: beforeAction
public function beforeAction($action)
{
$action->controller->layout = '//doctor';
$action->controller->view->registerJsFile('/jsLib/prj/doctor.js', ['position' => \yii\web\View::POS_END]);
return parent::beforeAction($action);
// TODO: Change the autogenerated stub
}
示例5: beforeAction
/**
**在请求交由action处理之前,判断用户属性,如果当前用户没有登录,或者登录用户没有管理员权限,那么抛出403异常,即只有管理员才能进入该管理模块.
* @param \yii\base\Action $action
* @return bool
* @throws HttpException
*/
public function beforeAction($action)
{
if (!User::getCurrent() || !Admin::getCurrent()) {
throw new HttpException(403, 'You are not an admin');
}
return parent::beforeAction($action);
}
示例6: beforeAction
public function beforeAction($action)
{
parent::beforeAction($action);
if (Yii::$app->user->isGuest || Yii::$app->user->status == 'user') {
Yii::$app->getResponse()->redirect(Yii::$app->user->loginUrl);
}
}
示例7: beforeAction
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
return $this->checkAccess($action);
}
return false;
}
示例8: beforeAction
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
//update users online information
$this->updateOnlineStatus($action);
// register visit by webspider
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$spider = YBoardSpider::find()->where(['user_agent' => $_SERVER['HTTP_USER_AGENT']])->one();
} else {
$spider = null;
}
if ($spider != null) {
$spider->setScenario('visit');
$spider->hits++;
$spider->last_visit = null;
$spider->save();
}
//menu fixed for Views
$approvals1 = YBoardPost::find()->unapprovedScope()->count();
$approvals2 = YBoardTopic::find()->andWhere(['approved' => 0])->count();
$reports = YBoardMessage::find()->reportScope()->unreadScope()->count();
$this->params['foroMenu'] = [['label' => Yii::t('app', 'Members'), 'url' => ['member/index']], ['label' => Yii::t('app', 'Pending') . ' (' . ($approvals1 + $approvals2) . ')', 'url' => ['moderator/approve'], 'visible' => Yii::$app->user->can('moderator')], ['label' => Yii::t('app', 'Reported') . ' (' . $reports . ')', 'url' => ['moderator/reported'], 'visible' => Yii::$app->user->can('moderator')]];
return true;
} else {
return false;
}
}
示例9: runAction
/**
* Runs an action within this controller with the specified action ID and parameters.
* If the action ID is empty, the method will use [[defaultAction]].
* @param string $id the ID of the action to be executed.
* @param array $params the parameters (name-value pairs) to be passed to the action.
* @return mixed the result of the action.
* @throws InvalidRouteException if the requested action ID cannot be resolved into an action successfully.
* @see createAction()
*/
public function runAction($id, $params = [])
{
$action = $this->createAction($id);
if ($action !== null) {
Yii::trace("Route to run: " . $action->getUniqueId(), __METHOD__);
if (Yii::$app->requestedAction === null) {
Yii::$app->requestedAction = $action;
}
$oldAction = $this->action;
$this->action = $action;
$result = null;
$event = new ActionEvent($action);
Yii::$app->trigger(Application::EVENT_BEFORE_ACTION, $event);
if ($event->isValid && $this->module->beforeAction($action) && $this->beforeAction($action)) {
$result = $action->runWithParams($params);
$this->afterAction($action, $result);
$this->module->afterAction($action, $result);
$event = new ActionEvent($action);
$event->result =& $result;
Yii::$app->trigger(Application::EVENT_AFTER_ACTION, $event);
}
$this->action = $oldAction;
return $result;
} else {
throw new InvalidRouteException('Unable to resolve the request: ' . $this->getUniqueId() . '/' . $id);
}
}
示例10: beforeAction
public function beforeAction($action)
{
if ($this->getIsInstalled() == true) {
\Yii::$app->getResponse()->redirect("admin.php");
return false;
}
return parent::beforeAction($action);
}
示例11: beforeAction
/**
* @inheritdoc
*/
public function beforeAction($action)
{
$adm = Adm::register();
if (!parent::beforeAction($action) || !$adm->user->can('AdmRoot')) {
return false;
}
return true;
}
示例12: beforeAction
/**
* @inheritdoc
*/
public function beforeAction($action)
{
if (!parent::beforeAction($action)) {
return false;
}
$this->resetGlobalSettings();
return true;
}
示例13: beforeAction
/**
* @inheritdoc
*/
public function beforeAction($action)
{
if ($this->checkAccess()) {
return parent::beforeAction($action);
} else {
throw new ForbiddenHttpException('You are not allowed to access this page.');
}
}
示例14: beforeAction
/**
* @inheritdoc
*/
public function beforeAction($action)
{
// Block installer, when it's marked as installed
if (Yii::$app->params['installed']) {
throw new HttpException(500, 'Application is already installed!');
}
Yii::$app->controller->enableCsrfValidation = false;
return parent::beforeAction($action);
}
示例15: beforeAction
public function beforeAction($action)
{
$aId = $action->id;
if ($aId == "register" && !$this->enableRegister) {
throw new \yii\web\NotFoundHttpException("Page not found");
} else {
return parent::beforeAction($action);
}
}