Cecil
Cecil

Reputation: 1619

CodeIgniter - Which function to use for URL's

Im building my first application using CodeIgniter, i need a bit of advice.

There are 2 functions that do the same thing and i was wondering which is the best to use.

Ok, so usually when im building a site, i link to the homepage by a simple / but if building on a directory, it will take back to the root public_html directory, with codeigniter i have found both

site_url()

and

base_url()

but, they both seem to do the same thing .. Just wondering if theres any difference, which one is better to use, etc etc.

Cheers,

Upvotes: 1

Views: 539

Answers (1)

Brandon Frohbieter
Brandon Frohbieter

Reputation: 18139

If you are using index.php

 site_url()

will include the index.php , and

 base_url()

will not include it.

If you are creating a url to pass, use

 site_url('images/img.png')

otherwise...

 base_url().'images/img.png' 

Upvotes: 2

Related Questions