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?
Asked
Active
Viewed 6,559 times
2

Nicholas Kajoh
- 1,451
- 3
- 19
- 28
-
Please http://stackoverflow.com/questions/6449386/base-url-function-not-working-in-codeigniter or you could simply call `echo base_url();` – keziah May 13 '16 at 00:01
-
1simply echo `site_url()` or `base_url()` ....! – NomanJaved May 13 '16 at 04:20
-
Also note if you are using CI3 and up it is now recommend that you set your base url in the config.php – May 13 '16 at 06:26
-
Okay, thanks guys! – Nicholas Kajoh May 13 '16 at 07:16
1 Answers
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

Pedro Lobito
- 94,083
- 31
- 258
- 268