Codeigniter:如何从不同的视图访问css文件


Codeigniter: how to access css files from different views?

我的问题是,我似乎无法在其他视图上加载.css和.js文件。唯一可以访问.css和.js文件的视图是我的default_controller的index()函数。目标文件夹没有任何问题,因为索引函数可以访问它。

我希望我的.css和.js文件可以被我的所有视图访问。

将以下链接添加到头文件

 <script src="<?php echo base_url() ?>js/hello.js" type="text/javascript" charset="utf-8"></script>
 <link rel="stylesheet" href="<?php echo base_url() ?>css/hello.css" type="text/css" charset="utf-8" />

对于css

 make the folder in codeigniter folder like following
       codeigniter->css->hello.css

对于js

 make the folder in codeigniter folder like following
       codeigniter->js->hello.js

您应该使用绝对URL加载所有JS和CSS文件:

<script src="<?php echo base_url() ?>path_to/index.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="<?php echo base_url() ?>path_to/index.css" type="text/css" charset="utf-8" />

现在,这样可以确保所有视图都可以使用您的所有文件。