in addition to piyush's answer, I need to mention something that will help to use site_url()
& base_url()
properly.
site_url("controller/method/args")
== base_url()
+ $config['index_page']
+ /controller/method/args
. You should use this to access pages.(Reference)
base_url("public/img/logo.png")
== base_url()
+ /public/img/logo.png
. You should use this to access resources such as images, stylesheets etc.(Reference)
Main difference between both functions is this part $config['index_page']
. If you have already removed the $config['index_page']
from the config.php
and you are using .htaccess
to rewrite the URLs, then both function will result the same. But it is a best practice to use the correct function for the correct purposes.
Hope this helps.