0

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 ?

1

1 Answer 1

3

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'
]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.