Codeigniter: Base_url doesn't seem to be working

扶醉桌前 提交于 2019-12-02 04:52:58

I am on the grid as well. After re-reading your question and doing a little testing (it works for me), I think what's happening is you forgot to load the url helper.

If you want the sites base url available to you to use in the application via base_url(), you need to load the url helper first. Either via config/autoload.php or load it manually in your controller.

Otherwise you could use config/constants.php to define constant variables:

define('BASE_URL', 'http://site.com');
define('BASE_PATH', '/path/to/CI/folder');

Just a quick note on base_url - might be a good idea to dynamically set this variable, as it will allow your site to support multiple domains.

(i.e. $config['base_url']    = ‘http://’.$_SERVER['HTTP_HOST'])

http://thecodeabode.blogspot.com/2010/10/codeigniter-supporting-multiple-domains.html expands a bit on this by giving scripts that take into consideration protocol and port.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!