Welcome Guest, Not a member yet? Register   Sign In
Loading own classes with interfaces
#2

[eluser]sl3dg3hamm3r[/eluser]
Hmmm that's a more tricky thing than I would have expected Sad Now I have the following autoloader in my config-file:

Code:
function __autoload($class) {
    //echo "__autoload: loading .$class<br>";
    //prevent CI and Pear classes from being loaded.
    if(!strstr($class, 'CI') && !strstr($class, 'MY_') && !stristr($class, 'PEAR')){
        require "$class.php";
    }
}

This fails as soon as CI tries to load e.g. its own Model-Class:
Message: require(Model.php) [function.require]: failed to open stream: No such file or directory

I don't know how I could prevent the autoloader from trying to load these classes?!?

Of course, another way would be to simply include my class in the controller's constructor where I would need it:
Code:
require_once(BASEPATH."application/models/OrderItemConfig.php");

But as a matter of fact, this won't work for me since I want to serialize the objects to my session and also deserialize it - which means the class needs to be included BEFORE the session reads and deserializes the data. And to include the above line into the config-file is also not a nice solution, I won't need the class everywhere and anytime.... When it comes to performance, this would be a bad solution.

Any other interesting, compelling ideas? Smile


Messages In This Thread
Loading own classes with interfaces - by El Forum - 12-28-2009, 08:45 AM
Loading own classes with interfaces - by El Forum - 12-29-2009, 03:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB