关于yii2里面的\yii\helpers\Url组件
2016-03-05 10:48
609 查看
在完成实验室网站的yii2移植过程中,发现在处理网页的跳转中需要经常用到\yii\helpers\Url组件,所以今天来总结一下。
//以http://localhost/basic/web/index.php?r=article/index为例
//base输出根目录
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
由于在打字过程中没有注意区分英文标点的切换,所以上面的语句如果有错,需要修改为英文标点即可。
//以http://localhost/basic/web/index.php?r=article/index为例
//base输出根目录
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
由于在打字过程中没有注意区分英文标点的切换,所以上面的语句如果有错,需要修改为英文标点即可。
相关文章推荐
- TP 模板中截取字符串
- php中mysqli_errno和mysqli_error的区别
- (9) PHP 随笔---Smarty模板引擎 已有模板和Smarty结合 11
- (8) PHP 随笔---Smarty模板引擎 复选框、下拉列表、单选按钮的应用 10
- (7) PHP 随笔---Smarty模板引擎 数组元素,面向过程 08--09
- (6) PHP 随笔---Smarty模板引擎 保留变量与配置变量的使用 06-07
- Zend Framework动作助手FlashMessenger用法详解
- (19) PHP 随笔---LAMP 系统常用命令
- (18) PHP 随笔---LAMP 权限操作
- (17) PHP 随笔---LAMP vi编辑器
- Zend Framework创建自己的动作助手详解
- Zend Framework动作助手(Zend_Controller_Action_Helper)用法详解
- php中的file函数
- php curl
- Zend Framework实现Zend_View集成Smarty模板系统的方法
- Zend Framework教程之视图组件Zend_View用法详解
- thinkphp-1
- ubuntu下安装PHP开发环境
- Zend Framework教程之视图组件Zend_View用法详解
- Zend Framework实现Zend_View集成Smarty模板系统的方法