CodeIgniter是一种典型的单入口框架,所有的路由请求都是经过根目录的index.php文件进行转发;
关于CodeIgniter的路径问题,一般用调用 url 辅助函数的 base_url()方法获取根目录的绝对路径,再进行路径的构建;
CI 中引入JS、CSS文件的方式
1
$this->load->helper('url'); 2
3
<script src=" echo base_url(); libraries/bootstrap/js/bootstrap.min.js"></script>4
<link href=" echo base_url(); libraries/bootstrap/css/bootstrap.min.css" rel="stylesheet">5
6
或7
<script src=" echo base_url('libraries/bootstrap/js/bootstrap.min.js'); "></script>8
<link href=" echo base_url('libraries/bootstrap/css/bootstrap.min.css'); " rel="stylesheet">注:文件地址以index.php文件存在的目录的起点(站点根目录)
可以在Controller获取 base_url()后通过参数传递给view;
CI 中图片路径的构建问题
1
【view.php】
2
$this->load->helper('url');
3
<img src=" echo base_url().'/assests/img/temp.png'; " >
本文介绍了CodeIgniter框架中如何使用base_url辅助函数来构建JS、CSS等资源文件的路径,并展示了两种实现方法。
686

被折叠的 条评论
为什么被折叠?



