php - Extending base_url() to base_url_admin() not working properly in CodeIgniter
My config config_backend.php (autoloaded) looks like this:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['my_admin_url'] = 'admin';
My helper admin_helper.php looks like this:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function base_url_admin()
{
$ci =& get_instance();
$ci->config->load('config_backend');
$ci->load->helper('url');
return base_url().$my_admin_url.'/';
}
My code in the view looks like this:
<a href="<?php echo base_url_admin(); ?>">Admin</a>
But the problem is that instead of the correct output like:
<a href="http://localhost/admin">Admin</a>
The link looks like:
<a href="http://localhost">Admin</a>
Funny thing is that when I do in helper e.g. this:
function base_url_admin()
{
$ci =& get_instance();
$ci->config->load('config_backend');
$ci->load->helper('url');
return "idiot";
}
it outputs something like:
http://localhost/admin/idiot
So, I assume that admin_helper is loaded, but I don't know how the admin appear there?
Any idea what am I doing wrong?
Answer
Solution:
You are supposed to return the
my_admin_url
config because you are not picking up the config item, you expect it to return it and/or the config returns a variable under the array key name i.e.$my_admin_url
. But to return it, you can do this: