CodeIgniter URL

启用查询字符串

    当使用index.php?c=product&m=view&id=345时,需要在application/config/config.php中设置$config[enable_query_strings为TRUE

添加URL后缀

    通过设置config/config.php$config[‘url_suffix’]这个参数,可以以example.com/index.php/products/view/shoes.html形式访问example.com/index.php/products/view/shoes


URI类

    URI类提供了帮助分割URI字符串的函数集合。如果使用URI路由功能,就可以通过分段来重新分发地址栏信息。URI类会被系统自动初始化,不必手动启动改功能。

$this->uri->setment(n): 将一个详细的URI从左至右分割为n段
例如 完整URL为 http://example.com/index.php/news/local/metro/crime_is_up, 则每个URI分段的编号为:1.news、2.local、3.metro、4.crime_is_up。默认情况下URI没有分段那么该函数返回FALSE。如果分段信息丢失,Segment函数还有第二个参数用来设置返回值。例如这样设置后,当发生错误时,函数就会返回'0'。

$product_id = $this->uri->segment(3,0);

如果没有该参数,应该像下面这样写:
if($this->uri->segment(3) === false){
   $product_id = 0;
}else{
   $product_id = $this->uri->setment(3);
}
$this->uri-slash_segment(n): 类似于 $this->uri->segment(), 不过它的第二个参数('','leading','both')会给返回的URI参数加上"/"线,如果不适用该参数,就会在后面增加斜划线,例如:
$this->uri->slash_segment(3);// segment/
$this->uri->slash_segment(3,'leading');// /segment
$this->uri->slash_segment(3,'both');// /segment/
$this->uri->slash_resegment(n) :这个函数功能与上面的相同,不同点是它允许开启CodeIgniter的URI路由功能时惊醒详细分割并重新分发URI信息并可以增加斜线"\"。

$this->uri->uri_to_assoc(n) :使用这个函数把每段信息存放到一个联合数组里
$this->uri->ruri_to_assoc(n) :同上面的相似,不过翻转了数组
$this->uri->assoc_to_uri() :把数组里的信息翻转成URI地址
$this->uri->uri_string() :返回一个包含完整URI信息的字符串,如:http://codeigniter.org.cn/user_guide/libraries/uri.html输出为news/local/345
$this->uri->ruri_string()
$this->uri->total_segments() :返回总的URI段数
$this->uri->total_rsegments() ;
$this->uri->segment_array() :返回一个包含URI分段的数组

$this->uri->rsegment_array();


URL辅助函数

加载方式:$this->load->helper('url');

site_url()   返回config.php中base_url设定值或自动获取
base_url()  返回config.php中设定的base_url
current_url()  返回页面的完整URL
uri_string()  返回页面的URI段
anchor(uri segments,text,attributes):创建基于本地站点URL的标准链接地址,即创建一个完整地址的a标签
anchor_popup()   和上面的相似,只是新窗口中打开
mailto()   创建邮件链接
safe_mailto()   安全邮件链接
auto_link()   自动把包含URL和email地址的字符串转换成链接
url_title()   输入一个字符串并创建用户友好的URL字符串
prep_url()   给URl加上"http://"
index_page()   返回config.php中设定的index_page
redirect() 页面跳转
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值