Welcome Guest, Not a member yet? Register   Sign In
Difference between base_url and site_url?
#1

[eluser]rolandpish[/eluser]
Hello.
I've installed codeigniter in: http://localhost/codeigniter

If I echo base_url() and site_url() they are practically the same: http://localhost/codeigniter

What is the difference between them?

Thanks in advance
#2

[eluser]davidbehler[/eluser]
I guess if you're not using index.php, then it's the same...otherwise there is a difference:
Code:
echo base_url(); // http://example.com/path/to/your/ci/install
echo site_url(); // http://example.com/path/to/your/ci/install/index.php
#3

[eluser]rolandpish[/eluser]
Thanks for your reply waldmeister.
In fact, I'm not using index.php (and using .htaccess to remove it from the URL), that's why they look the same.

Thanks!
#4

[eluser]Wilbur Himself[/eluser]
you should use site_url for constructing an URL for pass it to a function.

form example:
With base_url
Code:
base_url().'images/image.jpg'
With site_url
Code:
site_url('images/image.jpg')
#5

[eluser]rolandpish[/eluser]
Great. I need to pass some URL's to some functions. So this site_url is what I need in those situations.

Thanks a lot Wilbur!
#6

[eluser]skcin7[/eluser]
[quote author="Wilbur Himself" date="1241996898"]you should use site_url for constructing an URL for pass it to a function.

form example:
With base_url
Code:
base_url().'images/image.jpg'
With site_url
Code:
site_url('images/image.jpg')
[/quote]

I don't think that's necessarily true. It doesn't make a difference if you construct the URL as a parameter of base_url() or site_url(), or if you append the URL information after the function. I personally pass the URL information as a parameter because I think it keeps the code cleaner and easier to read.

base_url() is the best to use for those who use .htaccess to remove "index.php" from their URLs (which is most of us). site_url() will work just the same but there will be an added step for Apache to rewrite "index.php" from the URL, which is why I would recommend to use base_url().

I've always used site_url() but after doing a little research I definitely think base_url() is the better to use of the two.
#7

[eluser]CodeIgniteMe[/eluser]
site_url() is more portable in case you suddenly decide you don't want .htaccess anymore, so you won't need to rewrite everything from base_url() to site_url().

if you want a URL access to a resource (such as image, css, js), I suggest using base_url(), otherwise, site_url() would be a better solution IMHO.
#8

[eluser]Aken[/eluser]
[quote author="CodeIgniteMe" date="1334817893"]site_url() is more portable in case you suddenly decide you don't want .htaccess anymore, so you won't need to rewrite everything from base_url() to site_url().

if you want a URL access to a resource (such as image, css, js), I suggest using base_url(), otherwise, site_url() would be a better solution IMHO.[/quote]
Do this, mkay.




Theme © iAndrew 2016 - Forum software by © MyBB