base_url
?You will not get any Impotency error to set this and proceed. You can continue without setting, but you should know about HTTP header injection
You will get http://[::1]/
instead of your actual URL.
http://[::1]/
??This is temporary URL which set by CI by Default. This will point the root of your document.
::1
- Server address (localhost) Read More about this
base_url()
??Base URL should always point to root of your project folder. (outside application folder)
$config['base_url'] = 'http://localhost/path/to/project'; # If localhost
$config['base_url'] = 'http://stackoverflow.com/'; # If live
$config['base_url'] = 'http://stackoverflow.com/documentation'; # If live & inside subdomain (assume documentation is subfolder/subdomain)
base_url()
??Most common use is to find the right path to your js or css files.
<link rel="stylesheet" href="<?php echo base_url('styles/style.css');?>" />
<script src="<?php echo base_url('vendor/jquery/jquery.min.js');?>"></script>
Adding the code above in your view will produce HTML as below:
<link rel="stylesheet" href="http://localhost/path/to/project/styles/style.css" />
<script src="http://localhost/path/to/project/vendor/jquery/jquery.min.js"></script>
Links