php - Extending base_url() to base_url_admin() not working properly in CodeIgniter

69

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?

750

Answer

Solution:

You are supposed to return themy_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:

return base_url() . $ci->config->item('my_admin_url') . '/';

People are also looking for solutions to the problem: php - SQL query not ordering right

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.