首页 > Web开发 > 详细

024.CI4框架CodeIgniter辅助函数类之:URL辅助函数

时间:2020-03-01 00:42:16      阅读:96      评论:0      收藏:0      [点我收藏+]

01. PHP的CI4框架自带了很多好用的URL辅助函数,我选择了以下这些比较常用的列了出来,代码如下:

<?php namespace App\Controllers;

// http://127.0.0.1/CI4/public/index.php/hello/
class Hello extends BaseController
{
    public function index()
    {
        //http://localhost/CI4/index.php/news/local/123 0
        echo site_url(‘news/local/123‘) . ‘ 0<br>‘;
        //http://localhost/CI4/index.php/news/local/123 1
        $segments = array(‘news‘, ‘local‘, ‘123‘);
        echo site_url($segments) . ‘ 1<br>‘;
        //http://localhost/CI4 2
        echo base_url() . ‘ 2<br>‘;
        //http://localhost/CI4/blog/post/123 3
        echo base_url("blog/post/123") . ‘ 3<br>‘;
        //http://localhost/CI4/images/icons/edit.png 4
        echo base_url("images/icons/edit.png") . ‘ 4<br>‘;
        //hello 5
        echo uri_string() . ‘ 5<br>‘;
        //http://localhost/CI4/hello 6
        echo base_url(uri_string()) . ‘ 6<br>‘;
        //hello 7
        echo uri_string(‘http://some-site.com/blog/comments/123‘) . ‘ 7<br>‘;
        //index.php 8
        echo index_page() . ‘ 8<br>‘;
        //My News 9
        echo anchor(‘news/local/123‘, ‘My News‘, ‘title="News title"‘) . ‘ 9<br>‘;
        //My News 10
        echo anchor(‘news/local/123‘, ‘My News‘, array(‘title‘ => ‘The best news!‘)) . ‘ 10<br>‘;
        //Click here 11
        echo anchor(‘‘, ‘Click here‘) . ‘ 11<br>‘;
    }
}

技术分享图片

 

 

02.效果如下

技术分享图片

 

 

原创不易,如果您认为这篇文章有价值,认同作者的付出,可以微信二维码打赏任意金额给作者(微信号:382477247)哦,谢谢。

技术分享图片

024.CI4框架CodeIgniter辅助函数类之:URL辅助函数

原文:https://www.cnblogs.com/tianpan2019/p/12387282.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!