这是hardik vyas,CodeIgniter的新手,我对CodeIgnitr有基本的了解。我想在CodeIgniter中包括一个模板,但首先我需要在页面中包含一个外部样式表,但我做不到,我面临403错误。
这是我的代码:
控制器header.php
<?php
class Header extends CI_Controller{
function index(){
$this->load->view('header');
}
}
?>
查看header.php
<html>
<head>
<title>demo</title>
<link rel="stylesheet" type="text/css" href="/application/views/mystyle.css"/>
</head>
<body style="background-color: antiquewhite">
<h3 style="background-color: #990000;color: #ffffff">Hello</h3>
</body>
</html>
CSSmystyle.css
.red {
background-color: red;
}
请提供任何简单的方法来实现这一点,还请向我展示如何在CodeIgniter中包含模板的简单方法。
样式表不应位于CodeIgniter views
文件夹内。
你的文件夹应该是这样的:
/index.php
/css/mystyle.css
/codeigniter/application/controllers
/codeigniter/application/models
/codeigniter/application/views // <- no CSS in here
所以你的观点应该是:
<link rel="stylesheet" type="text/css" href="/css/mystyle.css"/>
如果你想在你的视图文件夹中使用CSS,那么我建议这样做:
文件夹
/codeigniter/application/views/css/mystyle.css
代码
<link rel="stylesheet" type="text/css" href="/codeigniter/application/views/css/mystyle.css"/>
把你的CSS放在你想放的地方,然后瞄准那个url。
请尝试将其放在文件夹"/views/mystyle.css
"中,例如"/"是站点的根目录,而不是CI安装。
从CI,您可以用调用它
<?= link_tag(base_url().'views/mystyle.css'); ?>
像这样尝试
<link rel="stylesheet" type="text/css" href="<?php echo base_url()?>views/mystyle.css"/>