Welcome Guest, Not a member yet? Register   Sign In
always problem with image path!
#1

[eluser]WebbHelp[/eluser]
Hi!

Everytime I create something with codeigniter I got problem with the paths.
Like a css file, image or something. I got the CSS file in the same directory as the view file but I can't reach it with only "style.css", how can I write a path to something that is in the same file as the index.php?

Like now, I use base_url() and include a JS file, but there is path's in that file to images.
How can I write the correct path to them, I got the JS file in same directory as index.php, the images is also in there!

Thanks //WebbHelp
#2

[eluser]stuffradio[/eluser]
Code:
<?php echo base_url(); ?>system/application/views/file.css
#3

[eluser]WebbHelp[/eluser]
Thanks but in a CSS file, I can't use PHP.

But isn't it enough with: /system/application/views/file.css
I thought it would work with only /style.css if the style.css were in same directory as index.php?

Thanks
#4

[eluser]WebbHelp[/eluser]
Somebody know?
#5

[eluser]WebbHelp[/eluser]
if somebody don't understand Smile

I got my css file in the same directory as index.php.
Why can't I write the link as only /style.css if they are in same directory?
And how can I do if I got a js file with image paths in? I can't write PHP in there so...

Thanks //WebbHelp

I would be very happy if someone can answer this, actually it is in hurry, sry Smile
#6

[eluser]WebbHelp[/eluser]
Do somebody know, how I can write the right path's to the image in my CSS file.
I tdoesn't matter if I change server/domain-name, the path's to the image will always work.
How can I get this work?

Thanks
#7

[eluser]stuffradio[/eluser]
[quote author="webbhelp" date="1261025557"]Do somebody know, how I can write the right path's to the image in my CSS file.
I tdoesn't matter if I change server/domain-name, the path's to the image will always work.
How can I get this work?

Thanks[/quote]

There's a "hack" to get around this. Write the CSS file in PHP. You use

Code:
<?php
header("Content-Type: text/css");

echo "background-image: url(" . base_url() . "file.css);";

?>

Like I said, that's a very hacky solution and I'm not sure that will work because I just typed this in here, but that's one way around it.
#8

[eluser]Unknown[/eluser]
Hi, I've spent the last, say, 3 hours of my time trying to figure this out - and I believe I've found the solution! I tested it on my development installation and it seems to work fine.

I found this .htaccess code on another thread. I tested it and it works:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Now how does this work? Well this is what I did:
1. create "css" and "img" folders in the system/application directory
2. put all your css and imgs into those folders, respectfully
3. when attaching a stylesheet, attach it this way (where "main_default.css" is your css file):
<link type="text/css" rel="stylesheet" href="<?php echo base_url(); ?>system/application/css/main_default.css " media="screen" />

4. regarding image path names, in css follow this example for a background image:
body {
margin: 0px;
padding: 0px;
background-image: url(../imgs/bg.jpg);
background-repeat: repeat;
}
5. again, regarding image path names, in html view files follow this example:
<body>
<span class="txt1">HELLO!</span>
&lt;?php echo img('system/application/imgs/bg.jpg'); ?&gt;
&lt;/body&gt;

I hope this helps. It helped me a lot.




Theme © iAndrew 2016 - Forum software by © MyBB