Oh, you shouldn’t be using base_url in an include or library load because base_url includes http://, etc.
Instead use a relative path, such as require_once(”../views/glowna_v.php”), or $this->load->view(‘glowna_v’).
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
September 05, 2007 11:19am
Subscribe [27]#46 / Sep 25, 2009 3:00pm
Oh, you shouldn’t be using base_url in an include or library load because base_url includes http://, etc.
Instead use a relative path, such as require_once(”../views/glowna_v.php”), or $this->load->view(‘glowna_v’).
#47 / Sep 25, 2009 3:56pm
thanks, on irc channel i have asked the same question and i have ended with this:
$BasePath = str_repeat("../", substr_count(dirname($_SERVER["SCRIPT_NAME"]), "/"));
$config['base_url'] = $BasePath . '/wl2/';and it is working now, thanks
#48 / Sep 25, 2009 4:51pm
I use this, because all the logic you guys are doing is already done by the browser.
$config['base_url'] = '/';#49 / Sep 25, 2009 5:20pm
$config['base_url'] = '/';Now that does not work everywhere. It works only if the site is at the root level. When online, that works but on localhost the site rarely is in the root level(I have tons of aliases set up in my localhost).
#50 / Sep 25, 2009 5:23pm
$config['base_url'] = '/sub-directory/';What is wrong with you people?
#51 / Sep 25, 2009 5:33pm
Haha.. Not to mention there are more elegant ways to work locally than subdir-ing the hell out of localhost. VirtualHost, anyone?
#52 / Sep 25, 2009 6:07pm
I was just pointing out that ‘/’ does not work for every situation. That subdirectory does not work for the same reason that I gave you before, only vice-versa 😊
Colin, tell me more about using vhost on localhost. Do you mean that I create hosts like “myproject”, “myproject2” etc. on the local machine and add those to vhosts (so the address would be http://myproject/)?
I know how to setup vhosts but havent done that on localhost before.
Automatic base_url on the wiki page works just fine both localhost and the actual domain so I havent bothered to use anything else but aliases.
#53 / Sep 25, 2009 8:05pm
cahva, I wouldn’t see the practicality of developing a site to live on the root locally then in a sub folder on the remote server.
Here’s a typical vhost entry I do:
<VirtualHost *:80>
DocumentRoot C:/local/www/williamsconcepts.com
ServerName local.williamsconcepts.com
ServerAlias *.local.williamsconcepts.com
<Directory "C:/local/www/williamsconcepts.com">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>Then I just add an entry to my hosts file (Windows)
127.0.0.1 local.williamsconcepts.com#54 / Sep 26, 2009 7:18am
Ok, thanks colin. I already turned my aliases to vhosts and all is working well 😊 With this config base_url can be just ‘/’ as you said.
#55 / Sep 28, 2009 6:58am
Wiki Page
thanks man , i have added this feature to my vunsy kernel, now it can know the base URL automatically
#56 / Nov 22, 2010 1:10am
i am stil having a problem when i click on submit i am redirected to http://localhost/CodeIgniter/form
which is my controller
Thanks
#57 / May 11, 2011 12:19pm
can the next lines work in a none code igniter framework
$root = “http://”.$_SERVER[‘HTTP_HOST’];
$root .= str_replace(basename($_SERVER[‘SCRIPT_NAME’]),”“,$_SERVER[‘SCRIPT_NAME’]);
thanks
#58 / Aug 21, 2011 7:08pm
Actually, CodeIgniter is already set up to handle different configurations between development, testing, and production.
In your config folder (default application/config) add a folder called ‘development’. Any configuration files you add to this folder will be loaded when in the development environment rather than the files in the config folder.
For your issue (and what I always do), copy config.php and database.php into application/config/development and change these settings to your development server settings. The same can be done for testing by adding a testing folder.
Now changing between environments is as simple as changing the current environment in your index.php file and without adding any extra lines of code.