0

I'm trying to build my own MVC framework, but I'm having problems with the autoloader.

I have the following directory layout:

-application
--Model
---RegiserUser.php
--Libs
---Base.php
---Model.php
---Model
--Controller
---Login.php

Model_RegiserUser extends Model which extends Base

The autoloader method is in the base class. I'm trying to emulate the way you load classes in Zend:

protected function __autoload( $class_name )
    {
        echo 'test';
        $filename = str_replace( '_', DIRECTORY_SEPARATOR, strtolower( $class_name ) ) . '.php';

        $file = ROOT . $filename;

        echo $file;

        if( !file_exists( $file ) ) {
            return FALSE;
        }
        include $file;
    }

I'm getting this error:

Fatal error: Class 'Model_RegisterUser' not found in C:\EasyPHP\data\localweb\application\controller\Login.php on line 31

Amal Murali
  • 75,622
  • 18
  • 128
  • 150
  • "I'm trying to emulate the way you load classes in Zend" - Zend\Loader is an independent component, so if you want the same behavior, there is no need to reinvent the wheel: http://framework.zend.com/manual/2.2/en/modules/zend.loader.standard-autoloader.html – Fabian Schmengler Feb 23 '14 at 12:16
  • Its more of a learning exercise – user3343171 Feb 23 '14 at 13:09

1 Answers1

1

strtolower is your problem... on a system like unix you try to load the file "registeruser.php" not "RegiserUser.php" (case sensitive ;))

dschibait
  • 104
  • 4