CSS无法与CodeIgniter一起使用 [英] CSS Not Working With CodeIgniter
问题描述
这是我的CI代码的一部分:
Here is a part of my CI code:
class page extends CI_Controller {
var $Page;
public function __construct() {
parent::__construct();
$this->Page = 1;
$this->load->model('posts_model');
$this->load->helper('url');
}
public function index() {
$data['posts'] = $this->posts_model->get_posts($this->Page);
$this->load->view('header');
$this->load->view('main', $data);
$this->load->view('footer');
}
function page_num($page) {
$this->Page = $page;
$data['posts'] = $this->posts_model->get_posts($this->Page);
echo $this->Page;
$this->load->view('header');
$this->load->view('main', $data);
$this->load->view('footer');
}
}
这是我的链接标签查看文件:
And this is link tag of my View File:
<link rel="stylesheet" type="text/css" href="css/indexpage.css" media="all"/>
当我打开索引文件(/ My-Site /)时,CSS可以正常工作,但是当我打开
When I open the index file (/My-Site/), CSS works fine, but when I open for
示例网址:
/ My-Site / page / page_num / 3,
" /My-Site/page/page_num/3 ",
页面打开,但没有CSS样式!
the page opens but with no CSS styles!
有人可以帮助我吗?
推荐答案
使用 base_url()
函数获取网站的网址
use base_url()
function to get the url of the site
base_url()
给出索引文件所在网站的网址。
base_url()
gives the url of the website where the index file is located.
例如: / My-Site /
,也可以将文件位置作为参数: base_url('/ css / indexpage.css')
然后将其用作< link rel = stylesheet type = text / css href =<?php echo base_url('/ css / indexpage.css'); ?> media = all />
or you can give the file location as the parameter: base_url('/css/indexpage.css')
then use it as <link rel="stylesheet" type="text/css" href="<?php echo base_url('/css/indexpage.css');?>" media="all"/>
这篇关于CSS无法与CodeIgniter一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!