Reputation: 5196
I have created a custom Url in Yii2
using
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'site/GetNewTicketsTechnician' => 'site/get-new-tickets-technician',
),
]
in web.php(I am using basic template).
But when I try to create a url using
yii\helpers\Url::to(['site/get-new-tickets-technician'])
It is generating url as site/GetNewTicketsTechnician
and not as
site/get-new-tickets-technician .
Can anybody knows the correct method to generate a url in Yii2
?
Upvotes: 0
Views: 1162
Reputation: 8400
Your problem is that last rule ('site/GetNewTicketsTechnician' => 'site/get-new-tickets-technician'
). It has site/get-new-tickets-technician
as target route, so when you use it with Url::to()
it will be used in reverse.
If you need that url to be callable (you have incoming requests on it), but don't want to include it for createUrl
-statements (generating links), you'll have to configure it as parse only:
[
'mode' => \yii\web\UrlRule::PARSING_ONLY,
'pattern' => 'site/GetNewTicketsTechnician',
'route' => 'site/get-new-tickets-technician'
]
Upvotes: 3