0

虽然这个问题在这个论坛上,但我想再问你一次。如何在 CI 中正确附加 css 和 js 文件(Code Igniter 框架)

这是我的代码:

视图/标题 - <link href="<?php echo base_url(); ?>assets/css/example.css" rel="stylesheet" media="screen">

自动加载.php -$autoload['helper'] = array('url');

但是css不起作用。感谢帮助

4

2 回答 2

0

我的方法是创建一个名为 assets 的文件夹并将它们放入您的 css 和 js 文件。

<script type="text/javascript" src="<?=base_url(); ?>asset/js/your_script.js"></script>
<script type="text/javascript" src="<?=base_url(); ?>asset/css/your_style.css"></script>

使用 base_url 而不是完整的域名很重要。然后将您的应用程序移动到新服务器很容易。

于 2015-02-20T15:51:10.857 回答
0

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"></scirpt>

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

于 2013-08-10T11:15:46.343 回答