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 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示