Difference between #113 and #114 of
Yii v2 snippet guide

Revision #114 has been created by rackycz on Sep 27, 2019, 7:27:01 AM with the memo:

edit
« previous (#113) next (#115) »

Changes

Title unchanged

Yii v2 snippet guide

Category unchanged

Tutorials

Yii version unchanged

2.0

Tags unchanged

tutorial,beginner,yii2

Content changed

[...]
As you can see in the snippet above, other controllers must contain row "use app\controllers\BaseController" + "extends BaseController"


**Access rights**
---
... text ...
 
 
**Nice URLs**
 
---
 
... text ...
 
 
**How to redirect web to subfolder /web**
 
---
 
... text ...
Every controller can allow different users/guests to use different actions. Method behaviors() can be used to do this. If you generate the controller using GII the method will be present and you will just add the "access-part"  like this:
 
 
```php
 
public function behaviors() {
 
  return [
 
    // ...
 
    'access' => [
 
      'class' => AccessControl::className(),
 
      'rules' => [
 
        [
 
          'allow' => true,
 
          'roles' => ['@'], // logged in users
 
          // 'roles' => ['?'], // guests
 
          'matchCallback' => function ($rule, $action) {
 
            // all logged in users are redirected to some other page
 
            // just for demonstration of matchCallback
 
            return $this->redirect('index.php?r=user/create');
 
          }
 
        ],
 
      ],
 
      // All guests are redirected to site/index in current controller:
 
      'denyCallback' => function($rule, $action) {
 
        Yii::$app->response->redirect(['site/index']);
 
      },
 
    ],
 
  ];
 
}
 
```
 
 
Details can be found here [https://www.yiiframework.com/doc/guide/2.0/en/security-authorization](https://www.yiiframework.com/doc/guide/2.0/en/security-authorization).
 
 
**Nice URLs**
 
---
 
... text ...
 
 
**How to redirect web to subfolder /web**
 
---
 
... text ...
 
 
**Auto redirection from login to desired URL **
 
---
 
... text ...
 
 
**What to change when exporting to the Interne**
 
---
 
- Delete file web/index-test.php
 
- In file web/index.php comment you 2 first lines containing YII_DEBUG + YII_ENV
 
7 0
4 followers
Viewed: 259 206 times
Version: 2.0
Category: Tutorials
Written by: rackycz
Last updated by: rackycz
Created on: Sep 19, 2019
Last updated: 7 months ago
Update Article

Revisions

View all history