thinkphp URL相关

具体详见tp文档。

此处仅做学习笔记。

后缀配置:

//    模板文件后缀名
    'TMPL_TEMPLATE_SUFFIX'=>'.html',
//    伪静态文件后缀名
    'URL_HTML_SUFFIX'=>'htm'

 U方法:

class IndexAction extends Action
{

    public function index()
    {
        p(U('show',array('uid'=>'1','uname'=>'adm'),'',true));
        $this->display('show');
    }
    
    public function show()
    {
        p($_GET);
        echo 'aaaa';
    }

}

以上结果:

 array(3) {
  ["uid"] => string(1) "1"
  ["uname"] => string(3) "adm"
  ["_URL_"] => array(6) {
    [0] => string(5) "Index"
    [1] => string(4) "show"
    [2] => string(3) "uid"
    [3] => string(1) "1"
    [4] => string(5) "uname"
    [5] => string(3) "adm"
  }
}
aaaa

说明:

U方法第一个参数是,控制器/方法。第二个参数是 传入的参数,支持数组和字符串

。第三个参数是伪静态后缀名(如果配置文件里是htm,此处为空或者是txt。则显示效果为

/zhuanpan/index.php/index/index/uid/1/uname/adm或
/zhuanpan/index.php/index/index/uid/1/uname/adm.txt

) 。第是个参数为是否跳转,如果设置为true则表示跳转到该URL地址。第五个参数是否显示域名

为什么要U方法。以为如果我的URL_MODEL为2.后来如果不支持URL_MODEL为2的情况。那么网站程序里的A标签的链接都要改了,非常麻烦。如果用了U方法。则只需要修改配置文件的URL_MODEL的值,非常的方便。

模板文件里使用U方法的格式为{:U('')}

原文地址:https://www.cnblogs.com/wenzichiqingwa/p/3481651.html