0

I want load a css file to my page. This my code for load css: <link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/emdad.css" />

Also, I set this code in my controller: $this->load->helper(array('form', 'url','html'));

Really, I am very confused. In this I write piece of my code.

Controller:

class Main extends CI_Controller{

    public function __construct(){
        parent::__construct();
           $this->load->library('emdadlib');
           $this->load->helper(array('form', 'url','html'));
    }

    public function index(){

        $this->load->view('structure',$data);
    }

    public function register(){

          $this->load->view('structure',$data);
    }

this is view(structure.php):

<html >
<head>
<link rel="stylesheet" type="text/css"  href="<?php echo base_url();?>css/emdad.css" />

base_url is: 127.0.0.1/emdad. I type 127.0.0.1/emdad/index.php/main/register in url browser. then page is loaded successfully but the css file does not handle.

halfer
  • 19,824
  • 17
  • 99
  • 186

2 Answers2

0

Use your css in layout folder which is in

../application/views/layout/

and when you calling loader you can add in controller file

Agha Umair Ahmed
  • 1,037
  • 7
  • 12
0

base_url() refers to the main website folder, for example c:\www\yourWebsite\app .

Edit: This is true if your config file has $config['base_url'] = '';

Try changing the link to your css like this:

<link rel="stylesheet" type="text/css"  href="<?php echo base_url();?>assets/css/emdad.css" />

Also, try debugging the view in chrome using the inspector (ctrl+i) and see if there are any information or errors in the console . If there are - please post them here.

Also - look here

Community
  • 1
  • 1
wick3d
  • 652
  • 6
  • 17
  • I try your suggest, but I have problem still.If I type in url browser "127.0.0.1/emdad" and set `link rel="stylesheet" type="text/css" href="css/emdad.css" />` in view,then , the css file is handled successfully!!! but the abov case that do nor working. – Javad Alirezaeyan Aug 12 '14 at 08:01
  • Well my suggestion is using a standard CI folder structure. Try debugging the base_url() - just echo it to the view and see where it points too. What doest the chrome inspector console say ? – wick3d Aug 12 '14 at 08:20
  • your suggest is correct, I solve my problem, thanks a lot wicj3d, you help me. – Javad Alirezaeyan Aug 12 '14 at 09:15
  • @Javad I'm glad I could help - don't forget to accept my anwser if it helped you – wick3d Aug 12 '14 at 09:26