Belicoff
Belicoff

Reputation: 69

Get full url of current webpage in Yii2

How to get the full URl in address bar to my Yii2 Model using yii\helpers\Url ?

I use $currentUrl = Yii::$app->request->url; but it return site/submit which is defined already in my UrlManager :

'urlManager'   => [
    'enableStrictParsing' => true,
    'enablePrettyUrl'     => true,
    'showScriptName'      => false,
    'rules'               => [
        '/'            => 'site/index',
        'site/submit'  => 'site/submit',
        'admin'        => 'admin/index',
        'admin/login'  => 'admin/login',
        'admin/index'  => 'admin/index',
        'admin/logout' => 'admin/logout',
        '/<url:.+>'    => 'site/index',
        'defaultRoute' => 'site/index',

    ],
],

Best regards,

Upvotes: 1

Views: 1267

Answers (2)

Golam Sorwar
Golam Sorwar

Reputation: 1615

Yii::$app->request->absoluteUrl

enter image description here

Plz follow this yii2 document

Upvotes: 2

Ketan Vekariya
Ketan Vekariya

Reputation: 352

Yii::app()->createAbsoluteUrl(Yii::app()->request->url)

Upvotes: 1

Related Questions