ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Automatic config[base_url]

September 05, 2007 11:19am

Subscribe [27]
  • #46 / Sep 25, 2009 3:00pm

    BrianDHall

    760 posts

    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

    lysiu

    2 posts

    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

    Colin Williams

    2601 posts

    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

    cahva

    662 posts

    $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

    wiredesignz

    2882 posts

    $config['base_url'] = '/sub-directory/';

    What is wrong with you people?

  • #51 / Sep 25, 2009 5:33pm

    Colin Williams

    2601 posts

    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

    cahva

    662 posts

    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

    Colin Williams

    2601 posts

    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

    cahva

    662 posts

    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

    Blaze Boy

    77 posts

    Wiki Page

    http://codeigniter.com/wiki/Automatic_configbase_url/

    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

    diasansley

    68 posts

    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

    Zion.b.y

    5 posts

    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

    jason.wolfsmith

    3 posts

    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.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases