【问题标题】:Stylesheet not getting attached in Codeigniter样式表未附加在 Codeigniter 中
【发布时间】:2012-12-28 11:31:38
【问题描述】:

我是 CI 新手,我尝试使用普通的 HMTL 文件作为模板。所以我在“应用程序/视图”中创建了一个名为“教育”的文件夹。我制作了 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”。但它也不起作用。

任何帮助

谢谢

【问题讨论】:

  • 您在哪个视图中加载 css?
  • 包含在头文件中

标签: php codeigniter-2


【解决方案1】:

您不应将样式表/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..

【讨论】:

  • 成功了。谢谢。另一件事,我从样式表中调用了未显示的图像。有什么想法吗?
  • @Roger 图片来自样式表?没听懂。。请多解释一下
  • 我明白了。我说的是我的样式表有一些类似背景图像的东西:url('images/bg.jpg');那么如何编辑呢?
  • @Roger 那应该可以正常工作..假设您的图像不在应用程序文件夹中..
  • 成功了。但是当我将css文件和Images文件夹保存在同一个文件夹中时,这就是我感到困惑的原因。我的错误;)
【解决方案2】:

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

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

文件 (your_site)/static/some.css

....
 some styles
....

【讨论】:

  • 成功了。谢谢。另一件事,我从样式表中调用了未显示的图像。有什么想法吗?
  • 把你的图片放在/static/images/image.jpg;在 css 中使用 background-image:url('/static/images/image.jpg');
  • 我尝试修改样式表值,但对我不起作用。我在放置“应用程序”、“系统”、“用户指南”文件夹的同一文件夹中创建了一个名为“教育”的文件夹。然后在 Education 文件夹中,我放置了 CSS 文件和 Images 文件夹。但它不起作用。 CSS 文件正在附加,但从 CSS 文件调用的图像文件没有获取路径。
  • 我改了。但它没有得到文件
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-04-11
  • 1970-01-01
  • 2019-04-26
  • 1970-01-01
  • 2014-09-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多