thinkphp U 方法总结
由于 ThinkPHP 支持各种不同的 URL 模式,另外还有分组模式,因此当环境发生变化时,有时候可能会改变 URL 模式,而 U 方法正是解 决不同配置情况下的 URL 统一问题。除了动态生成 URL 以自适应系统配置外,U 方法还有一个好处是可以自动加上伪静态后缀。 U方法语法 U('[项目://][路由@][分组名-模块/]操作?参数1=值1[&参数N=值N]') // 或者: U('[项目://][路由@][分组名-模块/]操作',array('参数 1'=>'值1' [,'参数N'=>'值N'])) U方法实例 U('list?cat_id=1&status=1') 模板中使用 U 方法 <a href="{:U('list?cat_id=1&status=1')}">超链接字符</a> <a href="index.php/Index/list/cat_id/1/status/1">超链接字符</a> <a href="{:U('list?cat_id='.$catList['cat_id'].'&status=1')}">超链接字符</a> 各种 URL 模式下的对比 普通兼容模式:index.php?m=Index&a=list&cat_id=1&status=1PATHINFO 模式:index.php/Index/list/cat_id/1/status/1REWRITE 模式 :Index/list/cat_id/1/status/1REWRITE 模式,伪静态后缀为 .html:Index/list/cat_id/1/status/1.htmlREWRITE 模式,使用 - 分隔 符与 .html 后缀:Index-list-cat_id-1-status-1.html常见 U 方法使用例子// 当前模块 list 操作 U('list?cat_id=1&status=1') // 其他模块操作 U('Blog/read?id=1') // 生成Blog模块的read操作,并且id为1的URL地址 // 其他分组 U('Admin-User/view?uid=1') // 生成Admin分组的User模块的view操作的URL地址 |
posted on 2012-06-12 09:48 Roc ps'king 阅读(362) 评论(0) 编辑 收藏 举报