答案 0 :(得分:0)
由于从根目录(index.php)显示所有内容,因此无需将URL放在CSS文件中,因为您可以将其放在根目录中。
答案 1 :(得分:0)
我使用两种解决方案:
<强>应用/控制器/ one.php 强>
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class One extends CI_Controller
{
public function index()
{
$this->load->helper('url'); // important!, check auto-load note
$this->load->view('one');
}
}
/* End of file one.php */
/* Location: ./application/controllers/one.php */
<强>应用/视图/ one.php 强>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>One</title>
<link rel="stylesheet" href="<?php echo base_url();?>css/style.css" type="text/css" media="screen"/>
</head>
<body>
<!-- page content -->
</body>
</html>
为了自动加载helper:
如果您发现整个过程中需要一个特定的帮助器 应用程序,您可以告诉CodeIgniter在系统期间自动加载它 初始化。这是通过打开来完成的 application / config / autoload.php 文件并将帮助器添加到 自动加载阵列。
这样就没有必要在每个控制器中编写$this->load->helper('url');
。
另一个解决方案是从主配置文件( application / config / config.php )中检索'base_url'项,并避免加载URL帮助文件:
<强>应用/控制器/ two.php 强>
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Two extends CI_Controller
{
public function index()
{
$this->load->view('two');
}
}
/* End of file two.php */
/* Location: ./application/controllers/two.php */
<强>应用/视图/ two.php 强>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Two</title>
<!-- We retrieve the config item -->
<link rel="stylesheet" href="<?php echo $this->config->item('base_url'); ?>css/style.css" type="text/css" media="screen"/>
</head>
<body>
<!-- page content -->
</body>
</html>
希望有所帮助