• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Make own objects

Sorry about that, it was just a bit of sarcasm.

Are you running PHP 5? Also, where are you defining your __autoload() function?

Yes I am running PHP 5 and my __autoload() is defined in MY_Controller.php which all my controllers are extending.

If i'm putting require_once "system/application/libraries/objects/game_serie.php"; in the controller which loads the page it works perfectly fine.

It's a function, not a method, and therefore needs to be defined in the global scope.

This is maybe a stupid question but isn't method and function the same thing, just different names? If not, what is the difference?

Semantically they are the same, but in actuality methods belong to objects.

Ok, I put the function outside the object in MY_Controller.php, and now I get this error message:
A PHP Error was encountered

Severity: Warning

Message: require_once(system/application/libraries/objects/CI_DB.php) [function.require-once]: failed to open stream: No such file or directory

Filename: libraries/MY_controller.php

Line Number: 4

Fatal error: require_once() [function.require]: Failed opening required 'system/application/libraries/objects/CI_DB.php' (include_path='.;C:\php5\pear') in C:\wamp\www\newnhl\system\application\libraries\MY_controller.php on line 4

I've searched for CI_DB.php but I don't know what that has to do with anything since I'm not trying to include that file.

CodeIgniter is not PHP5 compatible. It uses PHP4 style "class_exists()" function calls in other libraries which will initiate a call to your __autload function and cause you errors.

Alter your __autoload function to prevent CI from using it.
/** Library object class autoload **/
    function __autoload($class) {
        /* don't autoload CI_ or MY_ prefixed classes */
        if (strstr($class, 'CI_') OR strstr($class, 'MY_')) return;
        if(is_file($location = APPPATH.'libraries/objects/'.$class.EXT)) {
            include_once $location;

You could also place this function into the MY_Controller class and then add the PHP5 spl autoload register function into global context:

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.