A
A
Alexander Kovalev2016-07-31 00:37:17
Yii
Alexander Kovalev, 2016-07-31 00:37:17

Yii2 CNC how to specify in route the received parameter from the request?

Couldn't find or frame the question correctly. Faced the following problem:
url: site.ru/module/controller/?handler=action
I want to be redirected to site.ru/module/controller/action
I tried to specify this in the rules

[
      'pattern' => 'module/controller/<handler:\w+>',
      'route' => 'module/controller/<handler>'
]

Tell me how to write a rule correctly and can it be used in route?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrew, 2016-07-31
@alex_kovalevv

It is possible, as a crutch, to process and launch actions in actionIndex. The code is not exact, just to show the principle.

public function actionIndex($handler) 
{
  $this->runAction($handler, Yii::$app->request->getQueryParams());
}

A
Anton Natarov, 2016-07-31
@HanDroid

Strange syntax. Do you specify in config/main? It seems to go without patterns, in the spirit

'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                'Путь который должен быть показан - /' => 'куда обращается site/index',
                '<module>/<controller>/<action>' => '<module>/<controller>/<handler:action>',
            ],
        ],

I don’t know how you designed the handler and what it is in essence, but it worked for me with the component.

A
Alexander Kovalev, 2016-07-31
@alex_kovalevv

You see, ?handler=action comes after a redirect from a third-party server. Therefore, it turns out a url of the form
site.ru/module/controller/?handler=action , I cannot form a url in this module/controller/action format, I need to take the value from the handler and insert it into the path.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question