我正在基于tutorial by Anant Garg在PHP中创建自定义MVC框架:

CustomMVC
-app
    --controllers
        ---Controller.php
        ---HomeController.php   
    --models
        ---Home.php
    --views
-config
    --app.php
-lib
    --bootstrap.php
    --shared.php
    --database.class.php
-public
    --.htaccess
    --index.php
-tmp
-.htaccess

我的HomeController无法扩展Controller,我得到以下内容:

致命错误:第7行的/Applications/MAMP/htdocs/CustomMVC/app/controllers/homecontroller.php中找不到类'app \ controllers \ Controller'

它们都位于相同的命名空间下,并且位于同一目录下 . 我不知道为什么HomeController无法扩展基础控制器 . 有什么建议吗?

namespace app \ controllers;

Controller.php

namespace app\controllers;

use lib\Template;

class Controller {

    protected $_model;
    protected $_controller;
    protected $_action;
    protected $_template;

    public function __construct($model, $controller, $action) {

        $this->_controller = $controller;
        $this->_action = $action;
        $this->_model = $model;

        $this->_model =& new $model;
        $this->_template =& new Template($controller,$action);

    }

    function set($name,$value) {
        $this->_template->set($name,$value);
    }

    function __destruct() {
        $this->_template->render();
    }
}

HomeController.php

<?php

namespace app\controllers;

use app\controllers;

class HomeController extends Controller {

    function getHome($id = null,$name = null) {

    }

    function getAbout() {

    }

    function postContact() {

    }
}

这是lib ** shared.php中的自动加载功能**

function __autoload($className) {

    if ( file_exists(ROOT . DS . 'lib' . DS . strtolower($className) . '.php') )
    {
        require_once(ROOT . DS . 'lib' . DS . strtolower($className) . '.php');
    }
    else if ( file_exists(ROOT . DS . 'lib' . DS . strtolower($className) . '.class.php'))
    {
        require_once(ROOT . DS . 'lib' . DS . strtolower($className) . '.class.php');
    }
    else if ( file_exists(ROOT . DS . 'app' . DS . 'controllers' . DS . strtolower($className) . '.php'))
    {
        require_once(ROOT . DS . 'app' . DS . 'controllers' . DS . strtolower($className) . '.php');
    }
    else if( file_exists(ROOT . DS . 'app' . DS . 'controllers' . DS . strtolower($className) . '.class.php'))
    {
        require_once(ROOT . DS . 'app' . DS . 'controllers' . DS . strtolower($className) . '.class.php');
    }
    else if (file_exists(ROOT . DS . 'app' . DS . 'models' . DS . strtolower($className) . '.php'))
    {
        require_once(ROOT . DS . 'app' . DS . 'models' . DS . strtolower($className) . '.php');
    }
    else if (file_exists(ROOT . DS . 'app' . DS . 'models' . DS . strtolower($className) . '.class.php'))
    {
        require_once(ROOT . DS . 'app' . DS . 'models' . DS . strtolower($className) . '.class.php');
    }
    else
    {
        /* Error Generation Code Here */
    }
}