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 ...
随机推荐
- 内网渗透中的NTLM-Hash Relay
基础知识 NTLN和Net-NTLM 1.NTLM(V1/V2)的hash是存放在安全账户管理(SAM)数据库以及域控的NTDS.dit数据库中,获取该Hash值可以直接进行PtH攻击,我博客中前文也 ...
- redmine生产环境搭建
记录信息: 搭建基础应用及mysql 配置svn 配置自动重启 配置API开放 配置邮箱发送 开启数据库ip访问权限 确认用户组管理:配置用户同步 配置部门同步
- !important:element.style 覆盖样式问题
问题: 浏览器F12看到是这个样子. 但是我设置的样式是这样子. #iframe_close { width:750px; } 无论怎么设置样式,都无法覆盖掉element.style的样式,widt ...
- ASP.NET MVC 使用Redis共享Session
储存模式 1.InProc模式 这是ASP.NET默认的Session管理模式,在应用进程内维护Session. 2.StateServer模式 这是在服务器装了.NET环境后自带的一个StateSe ...
- MVC + ajaxform 文件上传
一.前端cshtml代码 <tr> <td width="130" align="right">添加附件:</td> @us ...
- easyui treegrid idField 所在属性中值有花括号(如Guid)当有鼠标事件时会报错,行记录一下
easyui treegrid idField 所在属性中值有花括号(如Guid)当有鼠标事件时会报错,行记录一下
- HDU-1881 毕业bg (01背包变形)
毕业bg Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissi ...
- Mapreduce其他部分
1.hadoop的压缩codec Codec为压缩,解压缩的算法实现. 在Hadoop中,codec由CompressionCode的实现来表示.下面是一些实现: 可分割性:可分割与不可分割的区别:文 ...
- SHU 413 - 添加好友
题目链接:http://acmoj.shu.edu.cn/problem/413/ 不难发现,这题是求C(n,1)+C(n,2)+C(n,3)+……+C(n,n-1)+C(n,n) 根据二项展开式有( ...
- Master Boot Record
https://en.wikipedia.org/wiki/Master_boot_record https://zh.wikipedia.org/wiki/主引导记录 A master boot r ...