简体   繁体   English

在 CodeIgniter 中包含外部样式表

[英]Including External stylesheet in CodeIgniter

This Is hardik vyas, new to CodeIgniter, I have basic know-how about CodeIgniter.这是 Hardik vyas,CodeIgniter 的新手,我对 CodeIgniter 有基本的了解。 I want to include a template into CodeIgniter, but first of all I need to include an external stylesheet in a page, But I can't, I am facing a 403 error.我想在 CodeIgniter 中包含一个模板,但首先我需要在页面中包含一个外部样式表,但我不能,我面临 403 错误。

Here is my code:这是我的代码:

Controller header.php控制器头文件header.php

<?php

class Header extends CI_Controller{

    function index(){
        $this->load->view('header');
    }
}
?>

View header.php查看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>

CSS mystyle.css CSS mystyle.css

.red {
    background-color: red;
}

Please provide any simple way to do this and also please show me a simple way about how to include a template in CodeIgniter.请提供任何简单的方法来执行此操作,并请向我展示如何在 CodeIgniter 中包含模板的简单方法。

Your stylesheet(s) should not be inside of the CodeIgniter views folder.您的样式表不应位于 CodeIgniter views文件夹中。

You folders should look like this:您的文件夹应如下所示:

/index.php
/css/mystyle.css
/codeigniter/application/controllers
/codeigniter/application/models
/codeigniter/application/views // <- no CSS in here

So your view should be:所以你的观点应该是:

<link rel="stylesheet" type="text/css" href="/css/mystyle.css"/>

If you want CSS in your views folder then I suggest this:如果你想在你的视图文件夹中使用 CSS,那么我建议这样做:

Folder文件夹

/codeigniter/application/views/css/mystyle.css

Code代码

<link rel="stylesheet" type="text/css" href="/codeigniter/application/views/css/mystyle.css"/>

Put your CSS wherever you'd like, then target that url.把你的 CSS 放在任何你想要的地方,然后定位那个 url。

Try putting it in the folder ' /views/mystyle.css ' for instance '/' being the root of your site, not your CI install.尝试将它放在文件夹“ /views/mystyle.css ”中,例如“/”是您站点的根目录,而不是您的 CI 安装目录。

From CI, you can then call it with从 CI 中,您可以调用它

<?= link_tag(base_url().'views/mystyle.css'); ?>

像这样尝试

 <link rel="stylesheet" type="text/css" href="<?php echo base_url()?>views/mystyle.css"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM