Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

url management in Yii 2

Tags:

php

yii

yii2

I have this url

http://example.com/index.php/controller_name/action_name?queryString=123

This url is working fine but when I am trying to use the queryString like in the old version of Yii

http://example.com/index.php/controller_name/action_name/queryString/123

I get an "unable to solve request" error.

I 've already enable prettyurl in my config file and the following url is working

 http://example.com/index.php/controller_name/action_name.

My config looks like :

'urlManager' => [
        'class' => 'yii\web\UrlManager',
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
            '<controller:\w+>/<id:\d+>' => '<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
            '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
            'module/<module:\w+>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>',
        ],
    ],

What am I missing?

like image 256
KB9 Avatar asked Apr 09 '14 12:04

KB9


People also ask

How to get URL in yii2?

To get the base URL of the current request use the following: $relativeBaseUrl = Url::base(); $absoluteBaseUrl = Url::base(true); $httpsAbsoluteBaseUrl = Url::base('https'); The only parameter of the method works exactly the same as for Url::home() .

How do I manage my URL?

Complete URL management for a Web application involves two aspects: When a user request comes in terms of a URL, the application needs to parse it into understandable parameters. The application needs to provide a way of creating URLs so that the created URLs can be understood by the application.

How to create URL in yii?

For example, you can use the following code to create a URL for the post/view action: use yii\helpers\Url; // Url::to() calls UrlManager::createUrl() to create a URL $url = Url::to(['post/view', 'id' => 100]);


1 Answers

Unfortunately this feature didn't migrate to Yii2, you can still define such rules manually

'books/view/queryString/<queryString:\w+>' => 'books/view',

Link on github with this issue

Because of many client API and Oauth servers don't work without encode

Sam Dark answer

like image 99
Alex Avatar answered Oct 11 '22 14:10

Alex