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 ...
随机推荐
- Mysql [Err] 1292 - Truncated incorrect DOUBLE value: 'a'
报错信息: [SQL] UPDATE 表 set times = 1 where type = 1 and times = 0 [Err] 1292 - Truncated incorrect DOU ...
- CLR 关于强命名程序集 .
如何创建强命名程序集(Strong Name Assembly) 创建一个强命名程序集首先需要获得一个用强命名实用工具 (Strong Name Utility,即SN.exe,.NET ...
- Unity3D笔记 英保通五 鼠标事件与GUI系统双击检测
一.如何使用GUI事件来检测鼠标是否按下的事件: 获取当前事件:var e:Event=Event.current: using UnityEngine; using System.Collectio ...
- ToStringBuilder类
文章来源:http://blog.csdn.net/zhaowen25/article/details/39521899 apache的commons-lang3的工具包里有一个ToStringBui ...
- html 自动弹出框
1.点击div外部隐藏, //*代表tip_box所包含的子元素 $('body').click(function(e) { var target = $(e.target); if(!target. ...
- Python面向对象之字段
类成员: 字段,方法,属性 属性是在一个函数方法前面加一个装饰器,伪造成为一个字段,调用的时候不需要加括号() 目的是把一个方法伪造成为一个字段,属性也是方法的一种,对这个方法进行改造就可以以 字段的 ...
- 《机器学习实战》中的splitDataSet函数
splitDataSet这个函数困扰了我好一阵子,为什么以某一特征值为标准进行划分数据集以后,变成了局部?例如,如果以第1个特征为0为标准进行划分,那么返回的结果集就是不含有此特征的结果集,如下图红框 ...
- HDU 6318 - Swaps and Inversions - [离散化+树状数组求逆序数][杭电2018多校赛2]
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=6318 Problem Description Long long ago, there was an ...
- 2018/03/27 每日一个Linux命令 之 cron
Cron 用于配置定时任务. -- 环境为 Ubuntu16-04 -- 先说说怎么配置一个简单的定时任务.直观的可以看到效果. 之前在网上查找资料,对Shell编程不熟悉的实在是很头疼,走了不少弯路 ...
- 将字符串类型转化为date类型
直接上代码 import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; pub ...