CodeIgniter - how to access base_url() in a helper? CodeIgniter - how to access base_url() in a helper? codeigniter codeigniter

CodeIgniter - how to access base_url() in a helper?


Unfortunately built-in helper functions are defined in the global php namespace, once you define a function with a name base_url you won't be able to define another one with the same name, so you can't load the original base_url function from the original helper "somwehere else" and use it.

For this reason CI's built-in helper files define function in if blocks like this:

if ( ! function_exists('FUNCTION_NAME'))// ...}

so even if you load the original helper file in your overridden version it doesn't create a fatal error, but also doesn't do anything meaningful.

In your concrete case, the base_url's implementation is basically a:

return get_instance()->config->base_url($uri);

you can lift it into your overridden version of base_url.