2016-09-27 120 views
1

我在web.php這條路線的規則:Yii2 - denyCallback好好嘗試一下正常工作

'my-stokkee/buy-credits' => 'user/buycredits', 

和訪問規則:

public function behaviors() 
    { 
     return [ 
      'verbs' => [ 
       'class' => VerbFilter::className(), 
       'actions' => [ 
        'delete' => ['post'], 
       ], 
      ], 
      'access' => [ 
       'class' => AccessControl::className(), 

       'ruleConfig' => [ 
        'class' => AccessRules::className(), 
       ], 
       'denyCallback' => function ($rule, $action) { 
        $this->redirect('login'); 
       }, 
       'rules' => [ 
        [ 
         'actions' => ['signup', 'create', 'reset-password'], 
         'allow' => true, 
         'roles' => ['?'], 
        ], 
        [ 
         'actions' => ['index', 'view', 'update', 'changepassword', 'buyaccount', 'buycredits', 'to-usd'], 
         'allow' => true, 
         'roles' => ['@'], 
        ], 
        [ 
         'actions' => ['manage'], 
         'allow' => true, 
         'roles' => ['admin'], 
        ], 
       ], 
      ], 
     ]; 
    } 

而不是重定向到登錄 ,它將重定向到my-stokkee/login。任何想法發生了什麼?

回答

2

嘗試使用完整路線。

return $this->redirect(['/site/login']); 
+0

這是行得通的。謝謝:) – Sasha

+0

Bah。你打了我3分鐘。 +1雖然。 – topher

2

的配置你的路由e.g使用路徑:

return $this->redirect(['login']); 

docs(重點煤礦)的$url參數爲:

的URL重定向到。這可以是在以下 格式之一:

  • 表示URL(例如, 「http://example.com」)的字符串
  • 表示URL別名的字符串(例如, 「@ example.com」)
  • 一個數組格式爲[$route, ...name-value pairs...](例如['site/index', 'ref' => 1]yii\helpers\Url::to()將用於 將數組轉換爲URL。

通過在當前請求的主機信息前加上任何相對URL將被轉換爲絕對URL。

相關問題