Welcome Guest, Not a member yet? Register   Sign In
Css links.
#1

[eluser]Young Caveman[/eluser]
I used search function, i found something but it did not work. Sad
I want to link a css file in my view, my .css is here:
Quote:index.php
system
user_guide
style
- style.css
But when i link the file with this:
Quote:<link type="text/css" rel="stylesheet" href="/style/style.css" />
It does not work.
Code:
<?=base_url();?>
failed, too. Sad
Anyone can help me? Thanks in advance.
#2

[eluser]Pascal Kriete[/eluser]
Are you using modrewrite? If yes, make sure it gives access to the style directory.
#3

[eluser]Young Caveman[/eluser]
[quote author="inparo" date="1215044426"]Are you using modrewrite? If yes, make sure it gives access to the style directory.[/quote]
:-( No I'm not using it.
#4

[eluser]Pascal Kriete[/eluser]
If you go there in your browser, can you see the file?

Also, is CI installed in the root or in a subfolder?
#5

[eluser]Young Caveman[/eluser]
[quote author="inparo" date="1215044956"]If you go there in your browser, can you see the file?[/quote]
Yes.
[quote author="inparo" date="1215044956"]Also, is CI installed in the root or in a subfolder?[/quote]
Subfolder. :| Locally:
Code:
http://localhost/codeigniter/
#6

[eluser]chaderick[/eluser]
I would do this in your controller:
Code:
// load html helper
$this->load->helper('html');

//load url helper
$this->load->helper('url');

// set name and path for css
// note the base_url() must be concatenated with the location of the css
$data['cssfile'] = base_url().'style/style.css';

// I assume you know this part, but just to be thorough:
// load the variable into the view
$this->load->view('name_of_your_view', $data);
then you can just use this in your view:
Code:
<?= link_tag($cssfile) ?>

Hope this helps!
#7

[eluser]Young Caveman[/eluser]
Oh yes. Thank you! Smile
#8

[eluser]luben[/eluser]
Hi guys, this is my first post in the forums.

I have the same problem that is stated here. I want to include css file in my header view, that will be included throught the whole site. However, I have a global css file that I need included every time I call the header view, e.g.

Code:
$this->load->view('global/header-view.php');

The solution above however does not seem sensefull, because I'll have to include a lot of source code in ALL my controllers to load this global css file.

Do you know, if there's easier way to include a css file in all pages, without writing 5-6 duplicate lines in all my controllers?

E.g. I want to avoid this code in ALL controllers:

Code:
// load html helper
$this->load->helper('html');

//load url helper
$this->load->helper('url');

// set name and path for css
// note the base_url() must be concatenated with the location of the css
$data['cssfile'] = base_url().'style/style.css';

My directory structure is like this:
Code:
/system
/css
---/main.css
/images

Thank you very much!
luben
#9

[eluser]luben[/eluser]
Hi guys, I resolved it and just want to comment it here, in case someone else has the same problem. All the code that I wanted to avoid in the controllers in discared.

I just had to put the css folder in the .htaccess file so requests to it are not redirected to index.php. This is the standard .htaccess file from CodeIgniter docs:

RewriteEngine on
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

The only difference is the css in bold.

now in the header view I just have this:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;&lt;?php echo $page_title ?&gt;&lt;/title&gt;
    &lt;meta http-equiv="content-type" content="text/html; charset=utf-8"&gt;
    &lt;link rel="stylesheet" href="/css/main.css" type="text/css"/&gt;
&lt;/head&gt;

best regards,
luben
#10

[eluser]puddles[/eluser]
Luben, where did you locate in your directory structure the .htaccess file?

Thanks....




Theme © iAndrew 2016 - Forum software by © MyBB