How to set the default controller in yii2
yii controller route
yii2 change default site controller
yii2 list routes
yii2 routing file
Did you try in your config:
'defaultRoute' => 'user/index'
Application Structure: Controllers, Therefore, if a URL is http://hostname/index.php , then the site controller will handle the request. You may change the default controller with the following To change default controller and action in Yii 2.0 put these two single line codes into correct location: Each application has a default controller specified via the [[yii\base\Application::defaultRoute]] property. When a request does not specify a route, the route specified by this property will be used.
Like few people already said, you need to add
defaultRoute in the configurations file.
Here is how it should look:
//config/web.php in basic template or
backend/config/main.php in advanced
$config = [ ... 'components' => [ ... ], 'params' => $params, 'defaultRoute' => 'user/index', ];
How to set the default controller in yii2, Did you try in your config: 'defaultRoute' => 'user/index'. Default Controller. To set your default controller as your homepage's controller on Yii PHP-Framework. You must modify the core defaults controller (site/index) on your /protected/config/main.php . return array( 'name' => 'Web Application', 'defaultController' => 'home ', );
This can be set within the config, see Default Controller:
[ 'defaultRoute' => 'main', ]
But note that this is closely related to routing, which can be completely customized by
urlManager component. Then if you want let's say
domain/profile to behave like
domain/user/profile then these rules for
urlManager might be another way to go:
'rules' => array( '<action:\w+>' => 'user/<action>', // <-- use UserController by default '<controller:\w+>/<id:\d+>' => '<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', '<controller:\w+>/<action:\w+>' => '<controller>/<action>', ),
Hopefully this will help someone :)
How to set default action and default controller on Yii Framework, We can set or change front page or home page of YII Driven web Application with simple Changes, we can do this with changing a default controller and a Change default controller and default login in yii2 advanced template By default yii2 advanced template redirects to url: site/login, when user is not login, to replace it with your own default login url:
web.php file from your configuration folder, and add the following:
'defaultRoute' => 'admin'
How to change default controller in YII2 Template?, Check out the throughout guide and learn how you can set/change default controller and default login in yii2 advanced template. Default Controller : Default Controller can be called , if no controller provided. Default action: Default Action is controller method, which will be called by the system automatically if no action is provided while calling controller. To change or set Default Controller in Yii, go to protected/config/main.php. replace ‘site'(Controller) with your controller . set default controller in yii
With yii2 I was able to do it in the urlmanager with:
'rules'=> [ ['pattern'=>'<action>', 'route'=>'controller/<action>'], ]
How to change default controller and action in Yii 2.0, To change this behaviour, change the default controller with the application configuration file which is web.php in config folder of your Yii 2.0 With layoutPath, you can have your own layout for ALL controllers and actions and you will leave the default layout intact. (as you said in your question). – Clyff Feb 15 '16 at 22:37. If that's not the case, please rewrite your question and be more clear on what you trying to accomplish. – Clyff Feb 15 '16 at 22:38.
How to set the default controller in yii2, I have UserControler and I run it in virtual server http://basic.com/index.php?r=user/index. How can I set up UserController and action index to be the default I recently change my app directory (all views and controllers are in new path) but I get new issue with my defaultController, views are not working for debug,gii and etc Exception 'yii\base\InvalidParamException' with message 'The vie
How to set the default controller in yii2, I have UserControler and I run it in virtual server http://basic.com/index.php?r=user/index. How can I set up UserController and action index to When a route contains the controller ID only, it implies that the default action of the specified controller is requested. By default, the default action is set as index. If you want to change the default value, simply override this property in the controller class, like the following:
yii2-backend-module/DefaultController.php at master · dmstr/yii2 , use yii\web\Controller;. /**. * Default backend controller. *. * Usually renders a customized dashboard for logged in users. */. class DefaultController extends When a Yii application starts processing a requested URL, the first step it takes is to parse the URL into a route. The route is then used to instantiate the corresponding controller action to handle the request. This whole process is called routing. The reverse process of routing is called URL creation,
- What have you tried? And did you google this: larryullman.com/2013/02/18/…
- How can i set default in Controller ?, ex, if login will another default router