Search code examples
csscodeignitercodeigniter-2base-url

CodeIgniter - Simple base_url question


I'm a bit confused here.

I have a simple controller which loads a view. The view contains a form and links some CSS files. I don't really want to do ../../css/global.cssin my link tag. I want to use the base_url() method and then go /css/.

I know a friend uses the following:

  <link href="{base_url}css/style.css" rel="stylesheet" type="text/css" />

However, I can't get that to work. He uses CodeIgniter 1.7 though, I'm using the latest (2.something) version. I'm new to CodeIgniter and I wanted to mess around with it, but I can't even link a simple CSS file :(

My view is in /logic/views/index.php, my css files are in /css/

Thanks a bunch.


Solution

  • I think your problem is that base_url is a function in ci 2+ so try this instead

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

    It depends how you defined base_url if you did an ending slash otherwise just add a slash so

    /css/style.css