Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Not Working With CodeIgniter

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"/>

When I open the index file (/My-Site/), CSS works fine, but when I open for

example the url :

" /My-Site/page/page_num/3 ",

the page opens but with no CSS styles!

Can any body help me please?

like image 234
Hamid Mohayeji Avatar asked Dec 05 '22 14:12

Hamid Mohayeji


2 Answers

use base_url() function to get the url of the site

base_url() gives the url of the website where the index file is located.

eg: /My-Site/

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"/>

like image 94
Vipin Jain Avatar answered Dec 23 '22 13:12

Vipin Jain


Try it.

you can use base_url() in your css. see below code.

<link rel="stylesheet" href="<?php echo base_url(); ?>css/style.css" type="text/css" media="all" />
like image 34
Abid Hussain Avatar answered Dec 23 '22 11:12

Abid Hussain