phpcodeigniterconfigurationdeclaration

What is the correct way to check if library/helper/core files are loaded in CodeIgniter


I'm using Codeigniter 2.

Appreciate if someone could show the correct way to check if the following files :


Solution

  • You can use the native PHP function class_exists() to determine if the class has been defined, before calling it. In same regard, using method_exists() will check if class method exists.

    Since helpers are collection of function, not methods, checking can be done using function_exists().

    if (class_exists('Library')) 
    {
        $this->library->myMethod();
    }
    

    For further info please refer to

    http://php.net/manual/en/function.class-exists.php.

    http://us.php.net/manual/en/function.method-exists.php