CodeIgniter Forums
CSS and Images with CodeIgniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: CSS and Images with CodeIgniter (/thread-3566.html)



CSS and Images with CodeIgniter - El Forum - 10-10-2007

[eluser]AdobeDelight[/eluser]
On my controller home.php, i have this simple line:

Code:
<?php
class Home extends Controller {

    function Home()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $data['message'] = 'Hello World';
        $this->load->view('home_view', $data);
    }
}
?>

On my view file home_view.php, i have this:

Code:
<html>
<head>
<title>myApp</title>
<link rel="stylesheet" type="text/css" href="styles.css" media="screen" />
</head>
<body>
<?=$message?>
</body>
</html>

When i loaded the page, i noticed that the style.css was not getting loaded properly, then i changed the stylesheet href to :

<link rel="stylesheet" type="text/css" href="system/application/views/styles.css" media="screen" />

and this worked. Does this means, from now on, i have keep entering "system/application/views/" front of all my css and images? Is there not a easier way of doing this?


CSS and Images with CodeIgniter - El Forum - 10-10-2007

[eluser]charlieD[/eluser]
The easiest way is to move things like css, javascript, images and flash onto the webroot so you can access them like href='images/something.gif' and 'css/style.css'. Files are relative to the index.php on the webroot.

Having your public web files somewhere on the root, outside of the views folder means that if you decide to move the application and system folders off the webroot, you won't need to change any references.


CSS and Images with CodeIgniter - El Forum - 10-10-2007

[eluser]imzyos[/eluser]
Yeah, i know hehehe, the best way to solve this USE FULL ROUTES example

check the code of this page,

link rel="stylesheet" href="http://codeigniter.com/themes/forum_themes/support/support.css" type="text/css" media="screen, projection" charset="utf-8" />
<link rel="stylesheet" href="http://codeigniter.com/themes/forum_themes/support/theme.css" type="text/css" media="screen, projection" charset="utf-8" />

Rick always use full paths http://codeigniter.com/themes/forum_themes/support/theme.css

with this you prevent it.

the other way its use routes relative to the INDEX FILE, the index file load ALL into HIM


CSS and Images with CodeIgniter - El Forum - 10-10-2007

[eluser]thurting[/eluser]
you should check out the assets helper. it is an easy way to set up your paths in your config file and then make a call in your view to display full paths.


CSS and Images with CodeIgniter - El Forum - 10-11-2007

[eluser]Crimp[/eluser]
Look up site_url() in the user guide.


CSS and Images with CodeIgniter - El Forum - 10-11-2007

[eluser]CI MikeD[/eluser]
personally,I have a separate folder called CSS on the same level ascodeigniters "system folder" - that is root. then access the csss with:

<link rel="stylesheet" media="screen" type="text/css" href="/css/file.css" />

I am not fond of full routes since it requires additional work ifyou want to reuse this code on website etc Smile

So if you have css in root then just tryx adding / to your example:

<link rel="stylesheet" type="text/css" href="/styles.css" media="screen" />


CSS and Images with CodeIgniter - El Forum - 10-22-2007

[eluser]Unknown[/eluser]
I was having a similar problem and then I remembered something I read about the file:

.htaccess

If you've edited yours to do a rewrite of your URI i.e. to eliminate the extra '/index.php/' part, you may need to add |css| to your rewrite condition so it looks something like this:

RewriteCond $1 !^(index\.php|images|css|robots\.txt)


CSS and Images with CodeIgniter - El Forum - 10-22-2007

[eluser]Kinsbane[/eluser]
[quote author="kodafox" date="1193068803"]I was having a similar problem and then I remembered something I read about the file:

.htaccess

If you've edited yours to do a rewrite of your URI i.e. to eliminate the extra '/index.php/' part, you may need to add |css| to your rewrite condition so it looks something like this:

RewriteCond $1 !^(index\.php|images|css|robots\.txt)[/quote]

This is what I use and it works good.


CSS and Images with CodeIgniter - El Forum - 11-13-2007

[eluser]Unknown[/eluser]
Hello,

Quote:I was having a similar problem and then I remembered something I read about the file:

.htaccess

If you’ve edited yours to do a rewrite of your URI i.e. to eliminate the extra ‘/index.php/’ part, you may need to add |css| to your rewrite condition so it looks something like this:

RewriteCond $1 !^(index\.php|images|css|robots\.txt)

i have this too and it works, IF i access my site without the third segment, i.e:

http://localhost/myweb/blog

BUT if i put the third segment, the css doesn't work properly, i.e:

http://localhost/myweb/blog/index


what did i do wrong ?? Thanks for helping.


CSS and Images with CodeIgniter - El Forum - 11-17-2007

[eluser]strogg[/eluser]
1. Did you add "css" to your .htaccess ?

Like this ;
RewriteCond $1 !^(index\.php|images|robots\.txt|css)

2. Did you load the URL Helper on your controller ?
$this->load->helper('url');

3. Then you can call your style file with base_url
<link rel="stylesheet" href='<?=base_url()?>css/yourstyle.css' type="text/css"/>