Welcome Guest, Not a member yet? Register   Sign In
Relative link to CSS
#11

[eluser]Colin Williams[/eluser]
It's really simple. Take the path "style/master.css" and match it with these URLs

http://www.example.com
http://www.example.com/about
http://www.example.com/user/22/edit

The resulting URLs being referenced are:

http://www.example.com/style/master.css
http://www.example.com/about/style/master.css
http://www.example.com/user/22/edit/style/master.css

Obviously that's an issue...
#12

[eluser]Colin Williams[/eluser]
Quote:I prefer not to use the base_url() thing because that just prints out www.example.com. Even if I changed it to localhost, it would be a hassle to change it back and forth when uploading it to my real web host.

So set it to "/" and leave the domain out of it. If your front controller is in a folder off the root--let's name it "ciapp"--then set your base_url to "/ciapp/" If that seems incredibly easy, that's because it is incredibly easy.

Quote:It seems that using getcwd() is considered useless. I just think that my previous post was not clear.

Nope. Clearly useless. Smile
#13

[eluser]John_Betong[/eluser]
Quote:[quote]
It seems that using getcwd() is considered useless. I just think that my previous post was not clear.

Quote:Nope. Clearly useless. Smile
 
 
Smile Smile Smile
When I first starting CI I was misled by the views being called without a relative folder. I assumed that if the CSS file was in the same folder then it would not need a relative path.
 
What is that expression about "assume makes an..."
 
 
 
#14

[eluser]ntheorist[/eluser]
[quote author="tokyotech" date="1247178984"]
I prefer not to use the base_url() thing because that just prints out www.example.com. Even if I changed it to localhost, it would be a hassle to change
[/quote]

set these settings in your config/config.php

Code:
$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$config['base_url'] .= "://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

You shouldn't have to worry about ever editing that again. I know how much a pain moving from local to test to live and back again can be. Also, for the database i usually create three groups of setting for each environment. $db['local'], $db['test'], $db['live'], which you could set based on the info returned by the new automatic base_url();

Also, i'm not sure if this affects css/js links, but look into the html <base> tag. It tells every (relative) link on your page to be relative to that url. Its good because its supported by almost every browser and as easy as
Code:
echo '<base href="'.base_url().'"/>';
The downfall with it tho is that it will break your page anchors (#'s) unless they are either made absolute (using current_url() perhaps?) or modified by javascript to point to the page . (jQuery could prolly also provide a solution in less than 5 lines of code)

_n
#15

[eluser]tokyotech[/eluser]
[quote author="TheFuzzy0ne" date="1247179924"]
EDIT: This would be my solution:
Code:
<link href="/application/views/style/master.css" rel="stylesheet" type="text/css" />;
[/quote]

I'm having no progress here. I followed those instructions and it still didn't load the stylesheet. I took a screenshot of my Dreamweaver and Firefox:

http://img263.imagevenue.com/img.php?ima...2_14lo.jpg
#16

[eluser]TheFuzzy0ne[/eluser]
What happens when you go to http://localhost/application/views/style/master.css?
#17

[eluser]tokyotech[/eluser]
[quote author="TheFuzzy0ne" date="1247268090"]What happens when you go to http://localhost/application/views/style/master.css?[/quote]

I get 404 Not found.

My WAMP has multiple websites, so I must go to http://localhost/veetleRefactored/ to start loading my default main.php controller, which in turn loads my header.php view.

This also gives me a 404 error: http://localhost/veetleRefactored/applic...master.css
#18

[eluser]Chad Fulton[/eluser]
For some reason everyone has forgotten that application resides in the system folder (or you could have just looked at the paths in the img he posted Wink).

You should us this:
Code:
<link href="/veetleRefactored/system/application/views/style/master.css" rel="stylesheet" type="text/css" />;

Or:
Code:
<base href="<?php echo base_url(); ?>system/application/views/style" />
<link href="master.css" rel="stylesheet" type="text/css" />;

Or (better still), this:
Code:
<link href="<?php echo base_url(); ?>'system/application/views/style/master.css" rel="stylesheet" type="text/css" />;
#19

[eluser]ntheorist[/eluser]
one other note, i prefer not to store css/js files within my system folder. I get a bit uneasy planting links anywhere that lead to system files, really.

also if you're running .htaccess to remove the index.php from your urls, one of the more popular uses employs removing direct web access to the system but allows for a system front controller :
Code:
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /clientname/system/index.php/$1 [L]

i don't know if you're using this set of rules but it may be blocking it. Also i'm thinking if you don't have some sort of system rule in place, it may be looking up localhost/clientname/index.php/system/application/views/style/master.css as controller = system, method = application etc

i would try quickly setting up a folder 'styles' in your root. Add it to your .htaccess if you're running it:
Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|styles|images|dev)
RewriteRule ^(.*)$ /clientname/index.php/$1 [L]

Place the css in there and try:

<link href="/styles/master.css" rel="stylesheet" type="text/css" />;

@chad using &lt;base href="&lt;?php echo base_url(); ?&gt;system/application/views/style" /&gt; wouldn't be such a good idea, as any relative anchor on the page would then point to the styles folder, ie <a href="products/view/123"> would link to http://localhost/clientname/system/appli...s/view/123

_n
#20

[eluser]tokyotech[/eluser]
[quote author="Chad Fulton" date="1247272795"]
You should us this:
Code:
&lt;link href="/veetleRefactored/system/application/views/style/master.css" rel="stylesheet" type="text/css" /&gt;;
[/quote]

This has fixed my problem. Thanks! Can you explain why the root is actually outside of "veetleRefactored"? It seems more logical to me to have the root be "veetleRefactored". See from this screenshot:

http://img233.imageshack.us/img233/8219/13140100.gif

I have 3 total websites in my WAMP. It just wouldn't make sense to have the root be at the same level as those 3 websites, because I'm only going to be accessing "veetleRefactored" files when I'm programming inside veetleRefactored.




Theme © iAndrew 2016 - Forum software by © MyBB