Yii2 introduces methods for generating specified URLs and images.
This article describes how Yii2 introduces the generation of specified URLs and images. We will share this with you for your reference. The details are as follows:
// /index?r=site/indexecho Url::to(['site/index']);// /index?r=site/index&src=ref1#nameecho Url::to(['site/index', 'src' => 'ref1', '#' => 'name']);// the currently requested URLecho Url::to();// /images/logo.gifecho Url::to('@web/images/logo.gif');// images/logo.gifecho Url::to('images/logo.gif');// http://www.example.com/images/logo.gifecho Url::to('@web/images/logo.gif', true);// https://www.example.com/images/logo.gifecho Url::to('@web/images/logo.gif', 'https');// /index?r=site/indexecho Url::toRoute('site/index');// /index?r=site/index&src=ref1#nameecho Url::toRoute(['site/index', 'src' => 'ref1', '#' => 'name']);// http://www.example.com/index.php?r=site/indexecho Url::toRoute('site/index', true);// https://www.example.com/index.php?r=site/indexecho Url::toRoute('site/index', 'https');echo Yii::$app->urlManager->createUrl('site/index')