参考文章:

http://blog.csdn.net/iefreer/article/details/21325371

以http://localhost/basic/web/index.php?r=article/index为例

echo \yii\helpers\Url::base();

//输出/basic/web

echo \yii\helpers\Url::base(true)

//输出http://localhost/basic/web

//home是输出首页,加上true是输出加域名的首页

echo \yii\helpers\Url::home();

//输出/basic/web/index.php

echo\yii\helpers\Url::home(true);

//输出http:://localhost/basic/web/index.php

//当前的Url

echo \yii\helpers\Url::current();

//输出/basic/web/index.php?r=article/index

//to和toRoute都是生成Url,后面加true都是生成带域名的Url

echo \yii\helpers\Url::to([‘article/add’]);

//输出/basic/web/index.php?r=article/add

echo \yii\helpers\Url::to([‘article/edit’,’id’=>1]);

//输出/basic/web/index.php?r=article/add&id=1

echo \yii\helpers\Url::to([‘article/add’],true);

//输出http://localhost/basic/web/index.php?r=article/add

echo \yii\helpers\Url::to([‘article/edit’,’id’=>1],true);

//输出http://localhost/basic/web/index.php?r=article/add&id=1

echo\yii\helpers\Url::toRoute([‘article/add’]);

//输出/basic/web/index.php?r=article/add

echo \yii\helpers\Url::toRoute([‘article/edit’,’id’=>1]);

//输出/basic/web/index.php?r=article/add&id=1

echo \yii\helpers\Url::toRoute([‘article/add’],true);

//输出http://localhost/basic/web/index.php?r=article/add

echo\yii\helpers\Url::toRoute([‘article/edit’,’id’=>1],true);

//输出http://localhost/basic/web/index.php?r=article/add&id=1

//to和toRoute之间的区别,传入string时,to 会直接把string当成url和toRoute则会解析

echo\yii\helpers\Url::to(‘article/add’);

//输出article/add

echo\yii\helpers\Url::toRoute(‘article/add’);

//输出/basic/web/index.php?r=article/add

Yii URL的更多相关文章

  1. YIi url美化

    一.Yii Url美化,配置urlManager组件 'urlManager' => [ 'enablePrettyUrl' => true, // 开启URL美化,可以去掉 index. ...

  2. yii url美化 urlManager组件

    yii的官方文档对此的解释如下: urlSuffix  此规则使用的url后缀,默认使用CurlManger::urlSuffix,值为null.例如可以将此设置为.html,让url看起来“像”是一 ...

  3. Yii url createUrl redirect相关

    一篇文章: 在yii中明明白白生成网址: 在Yii中经常要生成URL,不管是为了自动跳转还是仅仅是一个链接.下面对Yii中的URL生成做了一个总结.提示:以下controllerX代表控制器X,act ...

  4. IIS下 Yii Url重写

    下载URL重写组件 http://www.microsoft.com/zh-cn/download/details.aspx?id=7435 导入官方提供的.htaccess文件 Options +F ...

  5. Javascript and AJAX with Yii(在yii 中使用 javascript 和ajax)

    英文原文:http://www.yiiframework.com/wiki/394/javascript-and-ajax-with-yii /*** http://www.yiiframework. ...

  6. yii 常用一些调用 (增加中)

    调用YII框架中 jquery:Yii::app()->clientScript->registerCoreScript('jquery');        framework/web/j ...

  7. yii获取当前url和域名

    <?php //当前域名 echo Yii::app()->request->hostInfo; //除域名外的URL echo Yii::app()->request-> ...

  8. yii create url (二)

    在Yii中经常要生成URL,不管是为了自动跳转还是仅仅是一个链接.下面对Yii中的URL生成做了一个总结.提示:以下controllerX代表控制器X,actionX代表方法X.在Controller ...

  9. yii create url (一)

    1.$this->redirect这里的$this是当前的controller.可能是应用程序的也 可能是模块下的 这里仅将解一下第一个参能是url,当url是一个字符串时,它会自己动跳转 如$ ...

随机推荐

  1. HTTP之referer(网上搜集)

    1.打开httpfox抓包插件,在百度中搜索126.com,搜索项中点击网站入口,通过抓包工具,查看http请求 在http请求的Headers部分可见Referer. Referer http:// ...

  2. ThinkPHP 3.2 Token表单令牌

    /home/conf/config.php 中配置 'TOKEN_ON'=>true, 'TOKEN_NAME'=>'__hash__', 'TOKEN_TYPE'=>'md5', ...

  3. 【BZOJ-4561】圆的异或并 set + 扫描线

    4561: [JLoi2016]圆的异或并 Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 254  Solved: 118[Submit][Statu ...

  4. CommonJS/AMD/CMD/UMD概念初探

    1.CommonJS是一种规范,NodeJS是这种规范的实现. 1.1.CommonJS 加载模块是同步的,所以只有加载完成才能执行后面的操作. 参考: http://www.commonjs.org ...

  5. [转]vi command summary

    The following tables contain all the basic vi commands. *Starting vi* Command Description vi file st ...

  6. Unity 单例写法

    借鉴自:http://www.cnblogs.com/CodeCabin/p/unity_global_manager.html 实现复杂一些的全局控制,如切换游戏关卡等操作,更常用的方式是使用单例类 ...

  7. 电影发烧友必备知识-720P、1080P、4K的区别

    随着技术的进步,现在的影视作品的清晰度也越来越高,观众的体验也越来越好,普清的电影基本没人看了,尤其是影视爱好者现在都是看1080P或蓝光原盘.4K. 目前主流清晰度主要分为720P(高清).1080 ...

  8. LaTeX test

    \begin{equation} x^2+1=2 \end{equation} \begin{equation} x^2+y=3 \end{equation} $\dfrac{2\pi}{N}$

  9. Linux部分命令使用记录(实时更新)

    1. 实时监控文件内容变化 tail -f xxx 2. 查看文件前5行 head -5 xxx 3. ssh对话失效后关闭对话(可以避免直接关闭终端) ~. (好像显示有问题,按钮是 -.) 4. ...

  10. 常见linux命令释义(第四天)——bash部分

    学linux的时候,我跳过了一些很重要的东西.比如分区.还有vim的深入学习.分区没有学习是因为我装的是虚拟机,不知道是什么原因,格式化分区不能正常显示.至于vim,简单的增删改查我已经了解了.能够顺 ...