user3343171
user3343171

Reputation: 15

Autoloading classes in superclass

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

Upvotes: 0

Views: 71

Answers (1)

dschibait
dschibait

Reputation: 104

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

Upvotes: 1

Related Questions