this is url of my admin panel in yii
www.site.com/backend.php
I want to open admin panel by calling just like www.site.com/admin
Please Help to resolve this issue.
Use some "Google it skills"
In protected/config/{yourConfigName}.php
'components' => [
'urlManager' => [
'urlFormat' => 'path',
'showScriptName' => false,
'caseSensitive' => false,
],
],
and rename backend.php to admin.php
Related
I have following url for example:
http://mywebsite.com/testing/test
And I want it to be something like this depending on the current language:
http://mywebsite.com/en/testing/test
I have language stored in: Yii::$app->language
I tried to modify my URLManager (/config/web.php), but it doesn't work for me.
'urlManager' => [
'class' => 'yii\web\UrlManager',
'showScriptName' => false,
'enablePrettyUrl' => true,
'rules' => [
'/login' => 'site/login',
'/logout' => 'site/logout',
Yii::$app->language.'/'.'<controller:\w+>s'=>'<controller>/index',
Yii::$app->language.'/'.'<controller:\w+>/<id:\d+>/<title:\w+>'=>'<controller>/view',
Yii::$app->language.'/'.'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
Yii::$app->language.'/'.'<controller:\w+>/<action:\w+>/<id:\d+>/*'=>'<controller>/<action>',
],
],
Can You help me?
I found an extension. Even if you don't want to use it, you can look into it’s code to get an idea how it works. (Changing patterns / routing / etc.)
https://github.com/codemix/yii2-localeurls
I googled and searched here, but didnt find a solution... All that I found was subdomain to controller route... But thats not what I´m looking for...
So... here we go.
I have 2 subdomains:
sub-domain-a.site.com
sub-domain-b.site.com
And I have 2 modules:
module-a
module-b
I want Yii2 to redirect all requests to sub-domain-a to module-a and all requests to sub-domain-b to module-b...
so, if I have a controller in module-a, I just call:
sub-domain-a.site.com/controller-a-1
instead of
www.site.com/module-a/controller-a-1
same thing with sub-domain-b and module-b...
How can I accomplish this with Yii??
Thx!!
in config:
[
'components' => [
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
'sub-domain-a.site.com/controller-a-1' => 'module-a/controller-a-1',
],
],
],
]
In my app I have a module located in:
/frontend/modules/reports/controllers/TheModule.php/
frontend/modules/reports/controllers/views/the-module/index.php
The url for this is
frontend/web/reports/the-module/index
How can I have the url like this:
frontend/web/the-module/index ?
Because if I navigate to the module url as it is now, all the links in the main menu (which is common throughout the site) will get a /reports in their url.
Note that I am using the default url manager.
Try this in frontend configuration:
return [
// ...
'components' => [
// ...
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'the-module/<action>' => 'reports/the-module/<action>'
],
],
],
];
This regarding module creation inside backend folder.Example i have created a module name as "api". And also sccessfully created controller for that modules.
here is my urlmanager code:
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'rules' => [
'<module:\w+>/<controller:\w+>/<action:\w+>'=>'<module>/<controller>/<action>',
'<module:\w+><controller:\w+>/<action:update|delete>/<id:\d+>' => '<module>/<controller>/<action>',
],
]
when i access url with respect to module as "api" , controller as "country" and action as "create"
http://local2host.com/bootstrap/backend/web/index.php/api/country/create
it showing 404 Not Found error
Where i am going wrong?
The second rule will never work, Also you do not have to define the rules and the normal ones will work. So this
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
],
will make this link /website.com/core/contact/index work just fine.
But I am not sure why your route is not catching the first rule... strange. It should.
Better late then never.
For make module works you need to append it in config:
'modules' => [
......
'modulename' => [
'class' => 'app\modules\modulename\Module',
],
......
],
I want a view from another module to be rendered and I use path '//modulename/foldername/viewname'(without .php), but when I run it I get "Controller can't find the view" error. What do I do wrong? It used to work before. My version of Yii is 1.1.15.
EDIT:
These is my urlManager:
'urlManager' => array(
'class' => 'yupe\components\urlManager\LangUrlManager',
'languageInPath' => true,
'langParam' => 'language',
'urlFormat' => 'path',
'showScriptName' => false,
'cacheID' => 'cache',
'rules' => array(
)
But how can it be related to my problem? Doesn't urlManager has nothing to do with view aliases?
give it the full path to that file:
$this->render('application.modules.modulename.foldername.viewname' , $arrayData);