Welcome Guest, Not a member yet? Register   Sign In
custom mibrary
#1

[eluser]bartgrrr[/eluser]
Hi, I created a custom library to be used in my controller. The page works BUT I get the next errors in my logfile (note: I removed the timestamp):

ERROR - Severity: Warning --> include_once(application/core/MY_Spaarplan_library.php): failed to open stream: No such file or directory C:\wamp\www\verstandigsparen\application\config\config.php 366
ERROR - Severity: Warning --> include_once(): Failed opening 'application/core/MY_Spaarplan_library.php' for inclusion (include_path='.;C:\\php\\pear') C:\wamp\www\verstandigsparen\application\config\config.php 366

It seems that I need to put my library @ application\core and name it MY_Spaarplan_library. But I don't want to do that!

My Library (located @ application\libraries):
Code:
class Spaarplan_library
{

    public function berekenen($data)
    {
        ...
    }
}


My Controller (located @ application\controllers)
Code:
class Spaarplan extends MY_Controller
{
    function __construct()
    {
        ...
        $this->load->library('spaarplan_library');
        ...
    }

    public function berekenen()
    {
        ...
        $this->spaarplan_library->berekenen($this->data);
        ...
    }
}


A config snippet
Code:
$config['subclass_prefix'] = 'MY_';
...
function __autoload($class)
{
    if(strpos($class, 'CI_') !== 0)
    {
        @include_once( APPPATH . 'core/'. $class . EXT );
    }
}
#2

[eluser]TheFuzzy0ne[/eluser]
I haven't tested this, but it might work:

Code:
function __autoload($class)
{
    if(strpos($class, 'CI_') !== 0)
    {
        return;
    }
    
    foreach (['core/', 'libraries/', 'models/'] as $dir)
    {
        if (file_exists(APPPATH . $dir . $class . EXT))
        {
            include_once(APPPATH . $dir . $class . EXT);
            return;
        }
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB