2

I want to access my site url or base url from my controller in codeigniter 3. I tried $this->url->site_url() and $this->config->site_url(). None worked. Is it even possible?

4
  • Please stackoverflow.com/questions/6449386/… or you could simply call echo base_url(); Commented May 13, 2016 at 0:01
  • 1
    simply echo site_url() or base_url() ....! Commented May 13, 2016 at 4:20
  • Also note if you are using CI3 and up it is now recommend that you set your base url in the config.php Commented May 13, 2016 at 6:26
  • Okay, thanks guys! Commented May 13, 2016 at 7:16

1 Answer 1

4

Load URL Helper and function site_url()

This helper is loaded using the following code:

$this->load->helper('url');
echo site_url();

site_url()

Returns your site URL, as specified in your config file. The index.php file (or whatever you have set as your site index_page in your config file) will be added to the URL, as will any URI segments you pass to the function, and the url_suffix as set in your config file.

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

Segments can be optionally passed to the function as a string or an array. Here is a string example:

echo site_url("news/local/123");

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.