02 February 2020

How to fix base url in framework

We can set the base url or url in our framework to be automatically without change it wherever you want to place it in htdocs or localhost.

In CodeIgneter we will set it in application/config/config.php

Place this

$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

$config['base_url']    = "$root";

//$config[base_url] = "http://localhost/";

In Laravel we will set it in config/app.php

$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
return [
    'debug' => env('APP_DEBUG', false),
    //'url' => 'http://localhost',
      'url' => $root,
.......


So this is easy to fix all problem in your drive/ PC and your hosting wherever you want.

Share:

0 komentar:

Post a Comment

Blog Archive