24
Oct

Change default controller and default login in yii2 advanced template

share

Change default controller and default login in yii2 advanced template

By default yii2 template advanced template redirects to URL: site/login, when the user is not login, replace it with your own default login URL:

A. Add the below code on the backend main/config.php user component:

'components' => [
        'user' => [
            'identityClass' => 'common\models\User',
            'enableAutoLogin' => true,
         'loginUrl' => [ 'yourcontroller/youraction' ],
        ],

B. yii2 advanced template default controller is controllers/site controller.

You can change it to your module or controller name by putting the below configuration in main/config.php:

'defaultRoute' => 'yourcontroller',

Or if you have a module, then:

'defaultRoute' => 'module/controller',

Where a module is your module name and the controller is your controller name.
Then you can set the default action name in your controller file:

Class MyController extends Controller{
public $defaultAction = 'index';
}

You can also set rules in URLManager:

'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'enableStrictParsing' => false,
            'rules' => [
               'login'=>`yourcontroller/yourloginaction`,
                // ...
            ],
        ],
admin


Subscribe to get the latest blogs, insights, and innovations.

    By submitting this form, you agree to Ficode Technologies Limited Privacy Policy

    Linkedin Posts

    How To Generate SEO Friendly URL in Yii Framework

    How To Generate SEO Friendly URL in Yii Framework

    previous-blog-arrowPrevious
    Add Product Text Field with Survey ID in Cart

    Add Product Text Field with Survey ID in Cart

    next-blog-arrowNext