yii的url写法
Yii 各种url地址写法
echo Url::home();
生成入口地址/yii2test/frontend/web/index.php;
echo Url::base();
生成入口文件夹地址:/yii2test/frontend/web
echo Url::base(true);
生成带有域名的入口文件夹地址:http://localhost/yii2test/frontend/web
echo Url::to();
生成当前浏览器文档地址(同时携带参数)/yii2test/frontend/web/index.php?r=item%2Fview&id=4
Url::toRoute($route, $scheme = false); $route必须为数组格式;
echo Url::toRoute(['item/view']);
生成item为控制器,view为action,地址为:/yii2test/frontend/web/index.php?r=item%2Fview
还有其它例子:echo Url::toRoute(['site/index', 'src' => 'ref1', '#' => 'name']);
Url::to和toRoute() 非常类似。这两个方法的唯一区别在于,前者要求一个路由必须用数组来指定。 如果传的参数为字符串,它将会被直接当做 URL 。
Url::to() 的第一个参数可以是:
- 数组:将会调用 toRoute() 来生成URL。比如:
['site/index'],['post/index', 'page' => 2]。 详细用法请参考 toRoute() 。 - 带前导
@的字符串:它将会被当做别名, 对应的别名字符串将会返回。 - 空的字符串:当前请求的 URL 将会被返回;
- 普通的字符串:返回本身
以下是一些使用示例:

// /index.php?r=site/index
echo Url::to(['site/index']); // /index.php?r=site/index&src=ref1#name
echo 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 URL
echo Url::to(); // /images/logo.gif
echo Url::to('@web/images/logo.gif'); // images/logo.gif
echo Url::to('images/logo.gif'); // http://www.example.com/images/logo.gif
echo Url::to('@web/images/logo.gif', true); // https://www.example.com/images/logo.gif
echo Url::to('@web/images/logo.gif', 'https');

yii\helpers\Url::current() 来创建一个基于当前请求路由和 GET 参数的 URL

// assume $_GET = ['id' => 123, 'src' => 'google'], current route is "post/view" // /index.php?r=post/view&id=123&src=google
echo Url::current(); // /index.php?r=post/view&id=123
echo Url::current(['src' => null]);
// /index.php?r=post/view&id=100&src=google
echo Url::current(['id' => 100]);

记住 URLs
有时,你需要记住一个 URL 并在后续的请求处理中使用它。 你可以用以下方式达到这个目的:

// Remember current URL
Url::remember(); // Remember URL specified. See Url::to() for argument format.
Url::remember(['product/view', 'id' => 42]); // Remember URL specified with a name given
Url::remember(['product/view', 'id' => 42], 'product');

在后续的请求处理中,可以用如下方式获得记住的 URL:
$url = Url::previous();
$productUrl = Url::previous('product');
检查相对 URLs
你可以用如下代码检测一个 URL 是否是相对的(比如,包含主机信息部分)。
$isRelative = Url::isRelative('test/it');
yii的url写法的更多相关文章
- Yii 各种url地址写法
echo Url::home(); 生成入口地址/yii2test/frontend/web/index.php: echo Url::base();生成入口文件夹地址:/yii2test/fron ...
- jdbc应用程序连接Oracle rac的URL写法:
1.应用程序连接Oracle rac的URL写法: #Oracle(AMS) jdbc.driverClassName=oracle.jdbc.driver.OracleDriver jdbc.url ...
- Yii的URL助手
Url 帮助类 获得通用 URL 记住 URLs 检查相对 URLs Url 帮助类提供一系列的静态方法来帮助管理 URL. 获得通用 URL 有两种获取通用 URLS 的方法 :当前请求的 home ...
- jdbc url写法(集群)
mysql集群,jdbc url写法:jdbc:mysql://[host:port],[host:port].../[database][?propertyName1][=propertyValue ...
- yii create url (二)
在Yii中经常要生成URL,不管是为了自动跳转还是仅仅是一个链接.下面对Yii中的URL生成做了一个总结.提示:以下controllerX代表控制器X,actionX代表方法X.在Controller ...
- yii create url (一)
1.$this->redirect这里的$this是当前的controller.可能是应用程序的也 可能是模块下的 这里仅将解一下第一个参能是url,当url是一个字符串时,它会自己动跳转 如$ ...
- Yii 获取url 的一些方法
原文出处http://blog.csdn.net/iefreer/article/details/21325371 1. 获取url中的host信息: Yii::app()->request-& ...
- Yii 框架 URL路径简化
Yii 框架的訪问地址若不简化会让人认为非常繁琐.未简化的地址一般格式例如以下: http://localhost:80/test/index.php?r=xxx/xxx/xxx 若是带有參数会更复杂 ...
- 网站开发过程中的URL写法
在开发网页和服务器时发现,在很多地方需要写超链接 那么可以将超链接的使用者分为服务器和浏览器,以区分不同的写法 地址可能使用的情况: 1.跳转 2.转发 3.服务器资源地址 4.浏览器超链接 impo ...
随机推荐
- The request associated with the AsyncContext has already completed processing
Some time ago there was a problem with the servlet3.0, is in servlet in asynchronous processing data ...
- 关于IE和360安全浏览器如何添加百度搜索为默认的搜索引擎
以IE和360浏览器为例,细心的人可能会发现.IE浏览器默认使用的必应搜索引擎(cn.bing.com) 而360安全浏览器默认使用的好搜搜索引擎.(haosou.com),对于两种浏览器,我们都可以 ...
- 【笔记】javascript权威指南-第二章-词法结构
词法结构 //本书是指:javascript权威指南 //以下内容摘记时间为:2013.7.28 字符集 UTF-8和UTF-16的区别?Unicode和UTF是什么关系?Unicode转义 ...
- 9.11 Django关于母版语言的灵活用法
2018-9-11 12:45:38 还是这个连接 : http://www.cnblogs.com/liwenzhou/p/7931828.html 注意: 这节讲的是 母版语言的灵活用法! 可 ...
- webconfig的配置说明
转自 :http://www.cnblogs.com/kissdodog/archive/2013/04/16/3025315.html <?xml version="1.0" ...
- easyui_2----messager
<script> $.messager.alert("这是头","这是内容"); </script> 必须放在 $(function() ...
- 江南OJ 1151 - 还是晒太阳 - [状压DP]
题目链接:校内OJ的题目,就不放链接了. PS.可以说是本次9月月赛唯一的一道有一定难度的题目了. 题解: 考虑状压DP,假设 $sta$ 是一个二进制数,代表当前 $n$ 个人有几个是在队伍里的,剩 ...
- hdfs启用垃圾站功能
在core-site.xml文件中添加如下内容: ##开启回收站功能,设置保存7天删除数据信息 <property> <name>f ...
- angular2新建的项目上传github
前提1.git配置好,参见博文 git常用操作 2.angular2安装配置好,这个网上有很多教程,就不多说了,参见angular2快速起步 需要注意的是,大部分问题都是网络问题. 3.新建一个ng项 ...
- PDB、PD、PMP、RTB哪个更好?为品牌主解锁程序化购买的选择技巧
PDB.PD.PMP.RTB哪个更好?为品牌主解锁程序化购买的选择技巧 https://baijiahao.baidu.com/s?id=1620277114893208111&wfr=spi ...