参考文章:

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. js-新窗口打开页面

    window.open(basePath+"/web/homeIndex?code="+code); 1.超链接<a href="http://www.xxx.ne ...

  2. TODO: http框架HttpManager的实现

    提供get, post, 同步, 异步方式访问网络

  3. 【CodeForces 699A】Launch of Collider

    维护最新的R,遇到L时如果R出现过就更新答案. #include <cstdio> #include <algorithm> using namespace std; int ...

  4. python3 异常处理

    什么是异常 Python用异常对象(exception object)来表示异常情况.遇到错误会引发异常,如果异常对象未被处理或者捕捉,程序就会用回溯(traceback)终止执行. Raise语句: ...

  5. Python 素数判断;以及默尼森数

    1. 素数/质数 只能被2或者本身整除的正整数. 2. 默尼森数 P是素数且M也是素数,并且满足等式M=2^P-1,则称M为默尼森数. 编程小要求: 输出前5个默尼森数 1)最外层循环找素数 中间层循 ...

  6. 轻松搞定C语言中复杂的声明

    参考资料: [1] <C专家编程> 第3章 分析C语言的声明,p64-66

  7. codeforces 580D:Kefa and Dishes

    Description When Kefa came to the restaurant and sat at a table, the waiter immediately brought him ...

  8. Jenkins与Hudson的关系

    Jenkins的前身是Hudson(Sun开发),2010年从Hudson分支出来. 由于Sun被Oracle收购,Oracle拥有Hudson的商标所有权.分支出来的Jenkins将继续走open ...

  9. C++11之thread线程

    今天由于项目需求(其实是某门课的一个大作业,不好意思说出口啊...),想要使用多线程.相信大家一般用的是linux上的POSIX C或windows上的线程库,然而这些线程库以来于特定系统,并不“标准 ...

  10. Python 操作 mongodb 数据库

    原文地址:https://serholiu.com/python-mongodb 这几天在学习Python Web开发,于 是做准备做一个博客来练练手,当然,只是练手的,博客界有WordPress这样 ...