How can I rewrite url category/index?id=1 to fenlei/pingmiansheji in Yii 2?
if your point is show another url with pretty url you can user this:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'fenlei/pingmiansheji /<id:\d+>'=>'category/index',
],
Related
I upload a file using laravel backpack type => 'upload' view. It uploads successfully. But in the editing, it is not visible input. What is wrong if anyone knows to help me.
My Controller
$this->crud->addField([
'label' => "Document",
'name' => "document",
'type' => 'upload',
'upload' => true,
'crop' => false,
'disk' => 'vault',
]);
Below I attach the edit input view. It didn't show the already uploaded file name.
Try this
Try this
use ], 'both');
$this->crud->addField(
[
'label' => "Document",
'name' => "document",
'type' => 'upload',
'upload' => true,
'crop' => false,
'disk' => 'vault',
], 'both');
This is one of the column for the gridview. This is the URL it give me http://localhost/testing/apps/web/op/details/listing/particular
The URL that I wanted is
http://localhost/testing/apps/modules/op/controllers/listing/particular
I tried
'formOptions' => [ 'action' => ['/listing/particular'] ],
'formOptions' => [ 'action' => ['../listing/particular'] ],
'formOptions' => [ 'action' => ['apps/modules/op/controllers/listing/particular'] ],
The problem is no matter how I modified the URL, it just keep append whatever I typed behind http://localhost/testing/apps/web/(what i type)
Is there anyway to remove the web thing?
[
'class'=>'\kartik\grid\EditableColumn',
'attribute'=>'particular',
'editableOptions' =>
[
'inputType' => Editable::INPUT_TEXT,
'formOptions' => [ 'action' => ['listing/particular'] ],
'options' => [
]
]
],
Have you tried using yii\helpers\Url ?
use yii\helpers\Url;
Url::toRoute(['listing/particular'])
I am using the advanced template.
I created all my actions on the SiteController, so all my urls are domain.com/site/something, and I need to remove the word "site" from the url so it will be domain.com/something.
I tried the following rules based on this question
'urlManager' => [
'class' => 'yii\web\UrlManager',
'showScriptName' => false,
'enablePrettyUrl' => true,
'rules' => array(
'/<action:\w+>/<id:\d+>' => 'site/<action>',
'/<action:\w+>' => 'site/<action>',
'/noticia/<slug>' => 'site/noticia',
),
],
also tried this based on this other question:
'urlManager' => [
'class' => 'yii\web\UrlManager',
'showScriptName' => false,
'enablePrettyUrl' => true,
'baseUrl' => 'http://localhost/websites/transcita/app/frontend/web',
'rules' => array(
[
'pattern' => '<action:\w+>',
'route' => 'site/<action>'
],
[
'pattern' => '<action:\w+>/<id:\d+>',
'route' => 'site/<action>'
],
'/noticia/<slug>' => 'site/noticia',
),
],
but neither is not working. I get a 404 when I type domain.com/something.
I also tried without the first / and it didn't work either.
Any thoughts?
Another way:
'rules' => [
'<alias:\w+>' => 'site/<alias>',
],
Try with:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
// ...
// last rule
'<action:(.*)>' => 'site/<action>',
],
],
How can I rewrite urls in Yii2. I want to rewrite url
/post/index?id=1
to
/post/1-example
You need to add following rules code for urlManager in config/main.php(if advance template) or web.php.
[
'components' => [
'urlManager' => [
'showScriptName' => false,
'enablePrettyUrl' => true,
'enableStrictParsing' => false,
'rules' => [
'post/<id:\d+>-example' => 'post/index',
],
],
],
]
[
'components' => [
'urlManager' => [
'showScriptName' => false,
'enablePrettyUrl' => true,
'enableStrictParsing' => false,
'rules' => [
'post/<id:\d+>-<title:\w+>' => 'post/index',
],
],
],
]
You need to add below code to your backend/config/main.php under components section:
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',),
],
I'd posted just because ians should be generic for all entire project.
I have a problem with my Yii2 app.
I have a advanced-app with frontend and backend parts on different domains (subdomain). I use webvimark user management module, but I think the problem is not in it.
Frontend app -> domain.com
Backend app -> admin.domain.com
So I have problem with login in backend, it is not working.
I enter login and password, and after submit form I see login form again.
'user' => [
'identityClass' => 'webvimark\modules\UserManagement\models\User',
'enableAutoLogin' => true,
'identityCookie' => [
'name' => '_backendIdentity',
'domain' => 'admin.domain.com',
],
'class' => 'webvimark\modules\UserManagement\components\UserConfig',
],
and
'session' => [
'name' => 'BACKENDSESSID',
'cookieParams' => [
'domain' => 'admin.domain.com',
],
],
Any ideas?
Update #1: My config located: /backend/config/main.php
Update #2: There was a problem when transferring backend on a subdomain
Okey, there was a problem with the configuration of the module, as well as the wrong config in the frontend.
Backend:
'user' => [
'identityClass' => 'webvimark\modules\UserManagement\models\User',
'enableAutoLogin' => true,
'identityCookie' => [
'name' => '_backendIdentity',
'domain' => 'backend.test.dev',
],
'class' => 'webvimark\modules\UserManagement\components\UserConfig',
'on afterLogin' => function ($event) {
\webvimark\modules\UserManagement\models\UserVisitLog::newVisitor($event->identity->id);
},
],
'session' => [
'name' => 'BACKENDSESSID',
'cookieParams' => [
'domain' => 'backend.test.dev',
],
],
Frontend:
'user' => [
'identityClass' => 'webvimark\modules\UserManagement\models\User',
'enableAutoLogin' => true,
'identityCookie' => [
'name' => '_frontendIdentity',
'path' => '/',
],
'class' => 'webvimark\modules\UserManagement\components\UserConfig',
'on afterLogin' => function ($event) {
\webvimark\modules\UserManagement\models\UserVisitLog::newVisitor($event->identity->id);
}
],
'session' => [
'name' => 'FRONTENDSESSID',
'cookieParams' => [
'path' => '/',
],
],