![]() |
Getting base url for CSS or image loading, modify index.php - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Getting base url for CSS or image loading, modify index.php (/showthread.php?tid=19248) |
Getting base url for CSS or image loading, modify index.php - El Forum - 06-01-2009 [eluser]renownedmedia[/eluser] I modified my index.php and added this after the list of define()'s that CI uses: Code: 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? Getting base url for CSS or image loading, modify index.php - El Forum - 06-01-2009 [eluser]Thorpe Obazee[/eluser] I don't know if I understand what you mean but when you load, css, can't you use, Code: <?php echo base_url() . 'css/styles.css'; ?> Getting base url for CSS or image loading, modify index.php - El Forum - 06-01-2009 [eluser]renownedmedia[/eluser] It looks like base_url() is synonymous with str_replace("index.php", "", $_SERVER['PHP_SELF']), thanks. Getting base url for CSS or image loading, modify index.php - El Forum - 06-02-2009 [eluser]xwero[/eluser] An alternative is to use the base tag. Code: <base href="<?php echo base_url() ?>"> Getting base url for CSS or image loading, modify index.php - El Forum - 06-02-2009 [eluser]Dam1an[/eluser] [quote author="xwero" date="1243943649"]An alternative is to use the base tag. Code: <base href="<?php echo base_url() ?>"> 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? Getting base url for CSS or image loading, modify index.php - El Forum - 06-02-2009 [eluser]Thorpe Obazee[/eluser] 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. Getting base url for CSS or image loading, modify index.php - El Forum - 06-02-2009 [eluser]xwero[/eluser] base tag explanation : Quote:The BASE element defines the document's base URI for resolving relative URIs contained within the document.so yes you only need it once. Getting base url for CSS or image loading, modify index.php - El Forum - 06-02-2009 [eluser]Dam1an[/eluser] 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 here) and then I realised it was bargainphs blog lol |