yii2路由篇 --- Url类使用集锦

来源:互联网 发布:视频剪辑专用软件 编辑:程序博客网 时间:2024/05/23 15:03
### Url::to() 示例use yii\helpers\Url;// creates a URL to a route: /index.php?r=post%2Findexecho Url::to(['post/index']);// 带参数 url: /index.php?r=post%2Fview&id=100echo Url::to(['post/view', 'id' => 100]);// 元素 锚点 URL: /index.php?r=post%2Fview&id=100#contentecho Url::to(['post/view', 'id' => 100, '#' => 'content']);// 绝对 URL: http://www.example.com/index.php?r=post%2Findexecho Url::to(['post/index'], true);// https url: https://www.example.com/index.php?r=post%2Findexecho Url::to(['post/index'], 'https');// 相对url: /index.php?r=post%2Findexecho Url::to(['/post/index']);// 全局别名url: http://example.comYii::setAlias('@example', 'http://example.com/');echo Url::to('@example');// home page URL: /index.php?r=site%2Findexecho Url::home();// the base URL, useful if the application is deployed in a sub-folder of the Web rootecho Url::base();// the canonical URL of the currently requested URL// see https://en.wikipedia.org/wiki/Canonical_link_elementecho Url::canonical();// 记录跳转前地址Url::remember();echo Url::previous();

引用BKDUCK博客 http://www.bkduck.com/article/20

0 0