user1224233 user1224233 - 4 months ago 65
PHP Question

Codeigniter basepath system

In my view folder I putt one template and all its files but that template didn't load its css through codeigniter . Later I echo the basepath:

echo basepath;


This gives me this path:

/var/www/xxx/CI/system/


Doesn't it show the default path to that particular folder where the file is. My assumption is that it should give this path:

/var/www/xxx/CI/application/views


Thanks

Answer

You should place your css and other public assets in a folder in the site root.

For example:

/webapp
  /application
  /public
    /css
      /main.css
    /js
      /plugins.js
    /img
      /narwhals.png
  /system
  /index.php
  /license.txt

Then, from inside your view, you can use:

<link rel="stylesheet" type="text/css" media="all" href="<?php echo site_url('public/css/main.css'); ?>">

Also, in application/config/config.php you change the base_url like this:

$config['base_url'] = '';

It should be on line 17 of that file.