本文整理汇总了PHP中yii\web\Controller::beforeAction方法的典型用法代码示例。如果您正苦于以下问题:PHP Controller::beforeAction方法的具体用法?PHP Controller::beforeAction怎么用?PHP Controller::beforeAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\web\Controller
的用法示例。
在下文中一共展示了Controller::beforeAction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeAction
public function beforeAction($action)
{
if ($action->id == 'index' && Yii::$app->request->referrer !== null) {
Yii::$app->session->set('returnUrl', Yii::$app->request->referrer);
}
return parent::beforeAction($action);
}
示例2: beforeAction
public function beforeAction($action)
{
if ($action->id === 'result' || $action->id === 'success' || $action->id === 'fail') {
$this->enableCsrfValidation = false;
}
return parent::beforeAction($action);
}
示例3: beforeAction
/**
* @inheritdoc
*/
public function beforeAction($action)
{
if (Yii::$app->user->isGuest) {
return false;
}
return parent::beforeAction($action);
}
示例4: beforeAction
public function beforeAction($action)
{
if (in_array($action->id, $this->needAuthActions)) {
$this->layout = 'controlpanel';
}
return parent::beforeAction($action);
}
示例5: beforeAction
public function beforeAction($action)
{
if (!parent::beforeAction($action)) {
return false;
}
//Allow access when srbac is in debug mode
if (!\Yii::$app->getModule('rbac')->rbacCheck) {
return true;
}
// 先判断是否为module
$mod = $this->module !== null && $this->module->id != \Yii::$app->id ? $this->module->id . $this->delimeter : "";
$access = $mod . ucfirst($this->id) . $this->action->id;
// 先检查配置文件中的始终允许(modules配置中的$allowed),再检查数据库设置中的始终允许
$alwaysAllowed = \Yii::$app->getModule('rbac')->allowed;
if ($alwaysAllowed) {
if (in_array(strtolower($access), $alwaysAllowed)) {
return true;
}
}
// 检查数据库中存储的始终允许
$allowed = $this->allowedAccess();
if (array_key_exists($access, $allowed)) {
return true;
}
// Check for rbac access in RBAC Modules Components/SDbAuthManager
if (\Yii::$app->user->getIsGuest() || !\Yii::$app->authManager->checkAccess($access)) {
return $this->onUnauthorizedAccess();
} else {
return true;
}
}
示例6: beforeAction
public function beforeAction($action)
{
$config = [];
switch ($action->id) {
case 'quiz':
$config = ['steps' => ['question'], 'timeout' => 30, 'forwardOnly' => true, 'events' => [WizardBehavior::EVENT_WIZARD_STEP => [$this, $action->id . 'WizardStep'], WizardBehavior::EVENT_AFTER_WIZARD => [$this, $action->id . 'AfterWizard'], WizardBehavior::EVENT_STEP_EXPIRED => [$this, $action->id . 'StepExpired']]];
break;
case 'registration':
$config = ['steps' => ['profile', 'address', 'phoneNumber', 'user'], 'events' => [WizardBehavior::EVENT_WIZARD_STEP => [$this, $action->id . 'WizardStep'], WizardBehavior::EVENT_AFTER_WIZARD => [$this, $action->id . 'AfterWizard'], WizardBehavior::EVENT_INVALID_STEP => [$this, 'invalidStep']]];
break;
case 'survey':
$config = ['steps' => ['havePet', ['hasPet' => ['type', ['cat' => ['cat'], 'dog' => ['dog'], 'pet' => ['pet']]], 'noPet' => ['getPet', ['willGet' => ['get']]]]], 'autoAdvance' => false, 'defaultBranch' => false, 'events' => [WizardBehavior::EVENT_WIZARD_STEP => [$this, $action->id . 'WizardStep'], WizardBehavior::EVENT_AFTER_WIZARD => [$this, $action->id . 'AfterWizard'], WizardBehavior::EVENT_INVALID_STEP => [$this, 'invalidStep']]];
break;
case 'resume':
$config = ['steps' => []];
// force attachment of WizardBehavior
// force attachment of WizardBehavior
default:
break;
}
if (!empty($config)) {
$config['class'] = WizardBehavior::className();
$this->attachBehavior('wizard', $config);
}
return parent::beforeAction($action);
}
示例7: beforeAction
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
return true;
}
return false;
}
示例8: beforeAction
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
$request = Yii::$app->getRequest();
$response = Yii::$app->getResponse();
//is this a set-language post request?
if ($request->isPost && null !== ($language = $request->get('set-language'))) {
$languages = Yii::$app->params['languages'];
if (isset($languages[$language])) {
$response->cookies->add(new \yii\web\Cookie(['name' => 'language', 'value' => $language]));
}
$response->refresh();
return false;
}
//else, read language cookie
$cookies = $request->cookies;
if (!empty($cookies['language'])) {
Yii::$app->language = $cookies['language']->value;
}
//page size request?
$pageSize = filter_input(INPUT_GET, 'page_size', FILTER_VALIDATE_INT);
if ($pageSize && in_array($pageSize, Yii::$app->params['admin.page.sizes'])) {
Yii::$app->session->set('admin.page.size', $pageSize);
unset($_GET['page_size']);
}
return true;
}
return false;
}
示例9: beforeAction
public function beforeAction($action)
{
if (Yii::$app->request->enableSslRoutes) {
/**
* This piece of code here is to allow partial SSL for the minute while we cannot fully use SSL all over the site
*/
$found = false;
foreach (Yii::$app->request->sslRoutes as $route) {
if ($route == Yii::$app->controller->id . '/' . Yii::$app->controller->action->id) {
$found = true;
if (!Yii::$app->request->getIsSecureConnection() && !isset(error_get_last()['type'])) {
$sslUrl = Yii::$app->getUrlManager()->createAbsoluteUrl(Yii::$app->request->absoluteUrl, 'https');
return Yii::$app->controller->redirect($sslUrl)->send();
}
}
}
if (Yii::$app->request->getIsSecureConnection() && !$found && Yii::$app->controller->id . '/' . Yii::$app->controller->action->id !== 'site/error') {
$httpUrl = Yii::$app->getUrlManager()->createAbsoluteUrl(Yii::$app->request->absoluteUrl, 'http');
return Yii::$app->controller->redirect($httpUrl)->send();
}
}
if (Yii::$app->user->enableTier2 && !Yii::$app->user->getIsGuest() && Yii::$app->session->get('tier2Timeout') > time()) {
Yii::$app->session->set('tier2Timeout', Yii::$app->user->tier2Timeout);
}
return parent::beforeAction($action);
}
示例10: beforeAction
public function beforeAction($action)
{
if (Yii::$app->user->isGuest && $this->route != 'site/login') {
$this->redirect(['/site/login']);
}
if ($this->module->id == 'main' && Yii::$app->session['api_url'] == NULL) {
$this->redirect(['/site/index']);
}
$this->authRoute();
$menus = Yii::$app->params['menu'];
if ($this->app_code != null) {
$tools = (require Yii::getAlias('@backend/config/app/' . $this->app_code . '.php'));
if (!$tools) {
throw new InvalidConfigException('Loss your app config');
}
array_splice($menus, 1, 0, $tools);
}
$activeTag = '';
$menus = $this->normalizeMenu($menus, $activeTag);
if (isset($menus[$activeTag]['items'])) {
$this->leftMenu = $menus[$activeTag]['items'];
} else {
$this->leftMenu = [];
}
foreach ($menus as $key => $items) {
unset($menus[$key]['items']);
}
$this->topMenu = $menus;
return parent::beforeAction($action);
}
示例11: beforeAction
/**
* beforeAction function.
*
* @access public
* @param mixed $action
* @return void
*/
public function beforeAction($action)
{
$result = parent::beforeAction($action);
$options = ['tinymce' => \Yii::$app->urlManager->createUrl('/filemanager/files/tinymce'), 'properties' => \Yii::$app->urlManager->createUrl('/filemanager/files/properties')];
$this->getView()->registerJs("filemanager.init(" . json_encode($options) . ");", \yii\web\View::POS_END, 'my-options');
return $result;
}
示例12: beforeAction
public function beforeAction($action)
{
if ($this->action->id == 'pay-out') {
$this->enableCsrfValidation = false;
}
return parent::beforeAction($action);
}
示例13: beforeAction
public function beforeAction($action)
{
if ($action->id == 'error') {
$this->layout = 'main.php';
}
return parent::beforeAction($action);
}
示例14: beforeAction
public function beforeAction($action)
{
if (\Yii::$app->user->isGuest) {
return $this->goHome();
}
return parent::beforeAction($action);
}
示例15: beforeAction
/**
* @inheritDoc
*/
public function beforeAction($action)
{
if ($action->id == 'crop-avatar') {
$this->enableCsrfValidation = false;
}
return parent::beforeAction($action);
}