Part of the EllisLab Network
   
 
Getting base url for CSS or image loading, modify index.php
Posted: 01 June 2009 11:14 PM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  143
Joined  05-23-2009

I modified my index.php and added this after the list of define()‘s that CI uses:

define('SERVERPATH'str_replace("index.php"""$_SERVER['PHP_SELF'])); 

Based on the installation directory, SERVERPATH will equal the following:

http://localhost/test/index.php -> /test/
http://www.example.com/index.php -> /

Which is useful for me and probably a lot of users who do development on a localhost subdirectory and later upload to a real server.

My question is if there is a better way to do this, like if CI has this functionality built in without modifying a core file?

 Signature 

thomashunter.name

Profile
 
 
Posted: 01 June 2009 11:31 PM   [ Ignore ]   [ # 1 ]  
Lab Technician
RankRankRankRank
Total Posts:  1264
Joined  04-19-2008

I don’t know if I understand what you mean but when you load, css, can’t you use,

<?php echo base_url() . 'css/styles.css'?> 

The same thing goes with images.

 Signature 

PinoyTech - Web Development Blog

Profile
 
 
Posted: 01 June 2009 11:46 PM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  143
Joined  05-23-2009

It looks like base_url() is synonymous with str_replace(“index.php”, “”, $_SERVER[‘PHP_SELF’]), thanks.

 Signature 

thomashunter.name

Profile
 
 
Posted: 02 June 2009 02:54 AM   [ Ignore ]   [ # 3 ]  
Sr. Research Associate
RankRankRankRankRank
Total Posts:  4785
Joined  07-14-2006

An alternative is to use the base tag.

<base href="<?php echo base_url() ?>">
<
link type="text/css" rel="stylesheet" href="css/styles.css"
Profile
 
 
Posted: 02 June 2009 03:41 AM   [ Ignore ]   [ # 4 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  2674
Joined  05-18-2008
xwero - 02 June 2009 06:54 AM

An alternative is to use the base tag.

<base href="<?php echo base_url() ?>">
<
link type="text/css" rel="stylesheet" href="css/styles.css"

I’ve never seen it done like that, do you only need to specify the base once and it as used for all your css/js?

 Signature 

I’m building a Project Management System for my 3rd year Uni project, Sign up to the beta
Track my progress | Post of the day: UI Designs
Get full auto complete support for CodeIgniter in Eclipse

Profile
 
 
Posted: 02 June 2009 03:58 AM   [ Ignore ]   [ # 5 ]  
Lab Technician
RankRankRankRank
Total Posts:  1264
Joined  04-19-2008

I think it’s used by the currently loaded page as a base just like base_url() in CI.

Anyway, I believe that’s the first time, I’ve seen the html <base> tag.

 Signature 

PinoyTech - Web Development Blog

Profile
 
 
Posted: 02 June 2009 04:04 AM   [ Ignore ]   [ # 6 ]  
Sr. Research Associate
RankRankRankRankRank
Total Posts:  4785
Joined  07-14-2006

base tag explanation :

The BASE element defines the document’s base URI for resolving relative URIs contained within the document.

so yes you only need it once.

Profile
 
 
Posted: 02 June 2009 06:50 AM   [ Ignore ]   [ # 7 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  2674
Joined  05-18-2008

Wow, I was going through my RSS and thought it was a coincidence I found out about the base tag twice in one day (link [URL=http://pinoytech.org/blog/post/codeigniter-and-the-html-base-tag]here[/URL]) and then I realised it was bargainphs blog lol

 Signature 

I’m building a Project Management System for my 3rd year Uni project, Sign up to the beta
Track my progress | Post of the day: UI Designs
Get full auto complete support for CodeIgniter in Eclipse

Profile