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


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

    <?php namespace AppControllers;
    
    // 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)哦,谢谢。

  • 相关阅读:
    deepin之创建快捷idea启动方式
    python-docx读取doc,docx文档
    Jenkins节点配置-K8S云节点
    K8S创建用户RBAC授权
    在K8S中部署禅道zentao
    yum常用操作
    Git常用命令及方法大全
    rocket mq 1
    基于SpringBoot+LayUI+Freemarker+Mybatis的通用后台管理系统
    Struts+Servlet+JDBC网上手机销售系统
  • 原文地址:https://www.cnblogs.com/tianpan2019/p/12387282.html
Copyright © 2020-2023  润新知