Difference between CodeIgniter URL and Base URL

Hi. What is the difference between SiteUrl () and BaseUrl ()? In my previous project, this is the base url, but now in my new project this is Siteurl.Why is this happening? Is baseurl () deprecated

+7
php codeigniter
source share
3 answers

To resolve all your doubts, you should read the CodeIgniter Guide. Please click here

base url

Returns the base URL of your site as specified in your configuration file. Example: echo base_url ();

This function returns the same as site_url, without index_page or url_suffix.

Just like site_url, you can supply segments as a string or an array. The following is an example line: echo base_url ("blog / post / 123");

Site url

Returns the URL of your site as specified in your configuration file. The index.php file (or what you specified as the index_page site page in your configuration file) will be added to the URL, like any segments of the URI that you pass to the function and url_suffix, as indicated in your configuration file.

You are advised to use this function every time you need to generate a local URL so that your pages become more portable in case the URL changes.

Segments can optionally be passed to functions as strings or arrays. Here is an example line: echo site_url ("news / local / 123");

The above example will return something like: http://example.com/index.php/news/local/123

Here is an example of segments passed as an array: $ segment = array ('news', 'local', '123');

echo site_url ($ segments);

+4
source share

Base url for image / script / css. Site URL for URL for controller access

echo base_url(); // http://example.com/path/to/your/ci/install echo site_url(); // http://example.com/path/to/your/ci/install/index.php 

You can link to this forum:

http://ellislab.com/forums/viewthread/113974/

+5
source share

There is no doubt that the answers of kumar_v and nidheesh are absolutely correct. However, I would like to add when to use base_url () and site_url (). Basically, you can use site_url () when creating links for controllers, while base_url () can be used where we need to create URLs for resources such as loading a css or js file or some image.

I always prefer to use site_url () to create links to controllers or ajax urls and base_url () to load assets.

0
source share

All Articles