CodeIgniter Forums
base_url really necessary? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: base_url really necessary? (/thread-31357.html)



base_url really necessary? - El Forum - 06-16-2010

[eluser]Unknown[/eluser]
We're running codeigniter on a largish project. This means we have several different systems with the same code. A production environment, and a few development environments. Normally when we add new features we move the code from a development system to production.

One thing thats bugs me a little about CI is that it has code that is specific to a site, so you cant just copy over your docroot from a development server to a production server. Instead, you have to at least change $config['base_url'].

Is there a way around this? It would be nice if we could just move the whole docroot from development to production without having to worry about config settings.

edit: i guess we'll just copy everything but the config dir. exclude that whole dir. since we also need to have specific DB settings anyways.


base_url really necessary? - El Forum - 06-16-2010

[eluser]n0xie[/eluser]
I assume you are using scripts to retrieve the version to push live from a SCM. Just set your script to ignore the config folder (or at least config.php and database.php). We also ignore the index file since we have error reporting off on our live environments.


base_url really necessary? - El Forum - 06-16-2010

[eluser]WanWizard[/eluser]
Alternatively, use this:
Code:
if(isset($_SERVER['HTTP_HOST']))
{
    $config['base_url'] = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';
    $config['base_url'] .= '://'. $_SERVER['HTTP_HOST'];
    $config['base_url'] .= isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != '80' ? ( ':'.$_SERVER['SERVER_PORT'] ) : '';
    $config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
}
else
{
    $config['base_url'] = 'http://localhost/';
}

Which sets the base_url to whatever it gets passed from the webserver.

For my database.php we use what n0xie's suggests: it's not in our repository, it gets generated when you run the application setup.


base_url really necessary? - El Forum - 06-16-2010

[eluser]Kamarg[/eluser]
For your config settings you can always do an if/else or switch on $_SERVER['HTTP_HOST'] to distinguish which connection settings to use for dev and live environments. That way you don't need to ignore your config folder at all. Same goes for error_reporting in index.php. I've been using this method for my config files for the better part of a year without running into any issues.


base_url really necessary? - El Forum - 06-16-2010

[eluser]John_Betong[/eluser]
I define a LOCALHOST constant and use extensively:
Code:
// config.php
  define('LOCALHOST', 'localhost' === $_SERVER['SERVER_NAME']);

  if (! defined('ADSENSE'))  define('ADSENSE', ( ! LOCALHOST));  // maybe used in views

  $config['log_date_format'] = 'Y-m-d H:i:s';
  define('LOG_FILE_TODAY', $config['log_path'] .'log-' .date('Y-m-d') .'.php'); // maybe used in views



// MY_Controller.php
  $this->output->enable_profiler(LOCALHOST);


// view
if (LOCALHOST AND file_exists(LOG_FILE_TODAY) AND (filesize(LOG_FILE_TODAY) > 42))
{
echo "<div style='float:right; position:fixed;top:10px;right:0;font-size:2.2em;color:#f00'>";
    echo 'YES we have errors';    
echo '</div>';    
}
&nbsp;
&nbsp;
&nbsp;