douyuan9512 2012-08-25 04:17
浏览 70
已采纳

如何在codeigniter ci中加载javascript css文件

i wanna migrate my website into CI. i just simply modified from ci sample file welcome.php in index() function , i load the view to show. however , i put many javascripts and css files in the header file . and call it by $this->load->view('header'); but i can not load the javascript files correctly! Can anyone give me some tips ? it;s hard to configure how to set the correct path.

<script type="text/javascript" src="/assets/javascripts/order.js"></script> 
<script type="text/javascript" src="../assets/javascripts/order.js"></script>   
<script type="text/javascript" src="../../assets/javascripts/order.js"></script>    

my controller code as following

    class Welcome extends CI_Controller {

public function index()
{
    $this->load->helper('url');     
    $this->base = $this->config->item('base_url');

    $this->load->view('header');
    $this->load->view('welcome_message');


}

}

belows are my folder structure

enter image description here

  • 写回答

6条回答 默认 最新

  • doujumiao5024 2012-08-25 04:25
    关注

    put your assets folder with applications, system, assets

    not in application and simple load the url helper class in controller where you call the header view part something like

    $this->load->helper('url');
    $this->load->view('header');
    

    and simply use something like this in your header file..
    because $this->base_url() return the / folder..

    <script src="<?php echo $this->base_url();?>assets/javascript/jquery.js"></script>
    

    Changing the folder structure because access within the application folder is just for the core part that i know..

    here is the link if you want to know more about URL Helper

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 qc代码,修改和添加东西
  • ¥50 Unity的粒子系统使用shadergraph(内置管线)制作的一个顶点偏移shader,但是粒子模型移动时,顶点也会偏移
  • ¥15 如何用python处理excel的数据(极值标准化)
  • ¥15 三向应力状态求剪应力
  • ¥15 jupyter notebook如何添加libGL.so.1库
  • ¥20 easyPoi能否实现下拉多选或者复选框
  • ¥15 网桥在转发帧时,会变帧的源地址和目的地址吗?
  • ¥15 用Multisim设计汽车尾灯控制电路
  • ¥100 求用matlab求解上述微分方程的程序代码
  • ¥15 MAC安装佳能LBP2900驱动的网盘提取码