码迷,mamicode.com
首页 > 其他好文 > 详细

CodeIgniter框架零碎

时间:2017-12-04 15:03:15      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:mnt   target   http   输入   segment   get   display   lead   ota   

1. URI类
须知:
http协议中的URI和URL有什么区别: https://www.zhihu.com/question/21950864

技术分享图片
 1 <?php
 2 //假设当前URL为 http://xf.com/index.php/foods/dinner/noodle
 3 
 4 /**
 5  * segment($n[, $no_result=NULL])
 6  * URI路由: rsegment($n[, $no_result=NULL])
 7  * 从URI中获取指定段
 8  */
 9 $arr = $this->uri->segment(2, 0);  //dinner
10 
11 /**
12  * slash _segment($n[, $where=‘trailing‘])
13  * URI路由: slash_rsegment($n[, $where=‘trailing‘])
14  * 根据第二个的参数决定是否在返回结果的前面或者后面添加斜杠
15  */
16 $arr = $this->uri->flash_segment(3);  // noodles
17 $arr = $this->uri->flash_segemnt(3, ‘leading‘);  // /noodle
18 $arr = $this->uri->flash_segment(3, ‘both‘);  // /noodle/
19 
20 /**
21  * uri_to_assoc($n=3[, $default=array()])
22  * URI路由: ruri_to_assoc($n=3[, $default=array()])
23  * 将 URL的段转换为一个包含键值对的关联数组
24  */
25 //假设当前URL为 index.php/user/search/name/joe/location/UK/gender/male
26 $arr = $this->uri->uri_to_assoc(3);
27 $_default = array(‘name‘, ‘gender‘, ‘location‘, ‘type‘, ‘sort‘);
28 $arr = $this->uri->uri_to_assoc(3, $_default);
29 //返回结果如下
30 $arr = array(
31     ‘name‘ => ‘joe‘,
32     ‘location‘ => ‘UK‘,
33     ‘gender‘ => ‘male‘
34 );
35 
36 /**
37  * assoc_to_uri($array)
38  * 根据输入关联数组生成一个URI字符串
39  */
40 $arr = array(
41     ‘product‘ => ‘shoes‘,
42     ‘size‘ => ‘large‘,
43     ‘color‘ => ‘red‘
44 );
45 $str = $uri_str = $this->uri->assoc_to_uri($arr);  //product/shoes/size/large/color/red
46 
47 /**
48  * uri_string()
49  * URI路由: ruri_string()
50  * 返回一个相对的URI
51  */
52 $str = $this->uri->string();  //foods/dinner/noodle
53 
54 /**
55  * total_segments()
56  * total_rsegments()
57  * 返回URI的总段数
58  */
59 $n = $this->uri->total_segment();
60 
61 /**
62  * segment_array()
63  * rsegment_array()
64  * 返回URI所有的段组成的数组
65  */
66 $arr = $this->uri->segment_array();
67 //结果为:
68 $arr = array(
69     1 => ‘food‘,
70     2 => ‘dinner‘,
71     3 => ‘noodle‘
72 );
73 
74 ?>
View Code

 

CodeIgniter框架零碎

标签:mnt   target   http   输入   segment   get   display   lead   ota   

原文地址:http://www.cnblogs.com/pxf-ohyeah/p/7976882.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!