Yii2 关于 Url::toRoute 和Url::to 路径 例子

来源:互联网 发布:算法的乐趣代码 编辑:程序博客网 时间:2024/06/14 03:52

首先使用域名空间

use yii\helpers\Url;

Url::toRoute

// /index.php?r=site/indexecho Url::toRoute('site/index');// /index.php?r=site/index&src=ref1#nameecho Url::toRoute(['site/index', 'src' => 'ref1', '#' => 'name']);// /index.php?r=post/edit&id=100     assume the alias "@postEdit" is defined as "post/edit"echo Url::toRoute(['@postEdit', 'id' => 100]);// 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');

Url::to

// /index.php?r=site/indexecho Url::to(['site/index']);// /index.php?r=site/index&src=ref1#nameecho Url::to(['site/index', 'src' => 'ref1', '#' => 'name']);// /index.php?r=post/edit&id=100     assume the alias "@postEdit" is defined as "post/edit"echo Url::to(['@postEdit', 'id' => 100]);// 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');
原创粉丝点击