CodeIgniter Forums
Using CSS in CodeIgniter MVC - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Using CSS in CodeIgniter MVC (/showthread.php?tid=12729)



Using CSS in CodeIgniter MVC - El Forum - 10-29-2008

[eluser]Rey Philip Regis[/eluser]
Hi guys,

I need your help, in my view "view_products.php" I need to attach an external css file "default.css"

Before that here's my directory structure:
code_igniter
index.php
license.txt
.htaccess
system
appplication
fonts
...
.... and so on

so what I did is:
<link type="text/css" rel="stylesheet" href="<?php echo $_SERVER['DOCUMENT_ROOT'].'code_igniter/system/css/default.css'; ?>" />

also I put an .htaccess file like:
RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php

and I saved that in the code_igniter directory {look at my directory structure above}
then when I execute http://localhost/code_igniter/index.php
the css didn't work. Any advice on how to correct it, so the css file will render its style to my view.

Good day.

PhilipSmile


Using CSS in CodeIgniter MVC - El Forum - 10-29-2008

[eluser]Rey Philip Regis[/eluser]
Hi guys,

Ive just figured this out already using:

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]


Yahooooooo............
Goooogglee............

Yes...

PhilipSmile


Using CSS in CodeIgniter MVC - El Forum - 10-29-2008

[eluser]wr5aw[/eluser]
[quote author="rey_philip_regis" date="1225320741"]so what I did is:
<link type="text/css" rel="stylesheet" href="<?php echo $_SERVER['DOCUMENT_ROOT'].'code_igniter/system/css/default.css'; ?>" />[/quote]
I setup my app with a config item for the css folder then pass it to the view and do this:
Code:
<link type="text/css" rel="stylesheet" href="<?php echo $css_path; ?>default.css"; ?> />
I do the same for images, pd files, etc. Makes for a very portable app.

My config vars for the views looks like this:
Code:
$config = array (
  'page_settings' =>
  array (
    'image_path' => site_url()."/images/",
    'css_path' => site_url()."/css/",
    'pdf_path' => site_url()."/pdf/",
  ),
  ... etc.



Using CSS in CodeIgniter MVC - El Forum - 10-29-2008

[eluser]TVB_FSU[/eluser]
Thanks ... got it working by playing with the path in the image tag and then checking the image properties on the web .. until I finally nailed it!


Using CSS in CodeIgniter MVC - El Forum - 10-29-2008

[eluser]wr5aw[/eluser]
Glad you got it working. And as I mentioned in another post, site_url() is from the url helper. It needs to be loaded either manually or using autoload.