样式表未在Codeigniter中附加

时间:2012-12-28 11:31:38

标签: php codeigniter-2

我是CI的新手,我尝试使用普通的HMTL文件作为模板。所以我在'application / views'中创建了一个名为'education'的文件夹。我制作了header.php,navigation.php,content.php和footer.php文件。在我写的控制器中

class Education extends CI_Controller {
 function index() {
   $this->load->view('education/header');
   $this->load->view('education/navigation');
   $this->load->view('education/content');
   $this->load->view('education/footer');
 }
}

然后我访问了“http:// localhost:8080 / mvc / index.php / education /”

这样的链接

但样式表没有附加,它与文件位于同一文件夹中。我还尝试将样式表链接的href更改为“echo base_url(); application / views / education / style.css”。但它也不起作用。

任何帮助

感谢

2 个答案:

答案 0 :(得分:2)

您不应该在应用程序文件夹中保留样式表/ js文件/图像。将它们保留在某个文件夹(如“静态”)的应用程序文件夹之外,并使用base_url()

访问它们

一个好的文件/文件夹结构如下:

website_folder/
–––– application/
–––––––– config/
–––––––––––– autoload.php
–––––––––––– config.php
–––––––––––– ...
–––––––– controllers/
–––––––––––– examples.php
–––––––––––– index.html
–––––––––––– welcome.php
–––––––– ...
–––––––– views/
––––––––---- templates/
––––––––-------- backend.php
––––––––-------- frontend.php
–––––––––––– ....
–––––––––––– example.php
–––––––––––– index.html
–––––––––––– welcome_message.php    
–––– assets/
–––––––– css/
–––––––– js/
–––––––– images/
–––––––– templates/
––––––––---- frontend/
––––––––-------- css/
––––––––-------- js/
––––––––-------- images/
––––––––---- backend/   
––––––––-------- css/
––––––––-------- js/
––––––––-------- images/
–––––––– uploads/
–––––––– index.html
–––– system/
–––– user_guide/
–––– index.php
–––– license.txt 

参考thisthis ..

答案 1 :(得分:0)

文件:(your_site)/application/views/education/header.php

....
<LINK href="/static/some.css" rel="stylesheet" type="text/css">
....

文件(your_site)/static/some.css

....
 some styles
....