Getting base url for CSS or image loading, modify index.php |
[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?
[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'; ?>
[eluser]renownedmedia[/eluser]
It looks like base_url() is synonymous with str_replace("index.php", "", $_SERVER['PHP_SELF']), thanks.
[eluser]xwero[/eluser]
An alternative is to use the base tag. Code: <base href="<?php echo base_url() ?>">
[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?
[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.
[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.
|
Welcome Guest, Not a member yet? Register Sign In |