Skip to content

I can not understand the "helper" function #21

Open
@Daniel-ccx

Description

@Daniel-ccx

system/core/loader.php

I can not understand the "helper" function.

Why the "helper" has loaded "application/helper/test_func.php" and even try to check "system/helper/test_func.php" ?

There are too many "foreach" .

public function helper($helpers = array())
{
foreach ($this->_ci_prep_filename($helpers, '_helper') as $helper)
{
if (isset($this->_ci_helpers[$helper]))
{
continue;
}

        // Is this a helper extension request?
        $ext_helper = config_item('subclass_prefix').$helper;
        $ext_loaded = FALSE;
        foreach ($this->_ci_helper_paths as $path)
        {
            if (file_exists($path.'helpers/'.$ext_helper.'.php'))
            {
                include_once($path.'helpers/'.$ext_helper.'.php');
                $ext_loaded = TRUE;
            }
        }

        // If we have loaded extensions - check if the base one is here
        if ($ext_loaded === TRUE)
        {
            $base_helper = BASEPATH.'helpers/'.$helper.'.php';
            if ( ! file_exists($base_helper))
            {
                show_error('Unable to load the requested file: helpers/'.$helper.'.php');
            }

            include_once($base_helper);
            $this->_ci_helpers[$helper] = TRUE;
            log_message('debug', 'Helper loaded: '.$helper);
            continue;
        }

        // No extensions found ... try loading regular helpers and/or overrides
        foreach ($this->_ci_helper_paths as $path)
        {
            if (file_exists($path.'helpers/'.$helper.'.php'))
            {
                include_once($path.'helpers/'.$helper.'.php');

                $this->_ci_helpers[$helper] = TRUE;
                log_message('debug', 'Helper loaded: '.$helper);
                break;
            }
        }

        // unable to load the helper
        if ( ! isset($this->_ci_helpers[$helper]))
        {
            show_error('Unable to load the requested file: helpers/'.$helper.'.php');
        }
    }

    return $this;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions