PHP扩展了namespace \ class unknown错误

时间:2014-10-23 00:17:28

标签: php class oop namespaces

这是我的父类代码:\ core \ controller \ controlmaster

<?php
namespace core\controller;

class controlmaster{
private $model_base = null;

//public function __construct(){
    //always start session for any loaded controller
    //session_start();        
//}

public function _loadModels($models){
    $file = dirname(dirname(__DIR__)).DIRECTORY_SEPARATOR.$this->model_base.$models.".php";
    $file_alloc = str_replace("\\","/",$file);
    if(file_exists($file_alloc)){
        require($file_alloc);
        $models_name = $this->model_base.$models;
        return new $models_name();  
    }
}

public static function _setModelBase($model_location){
    $this->model_base = $model_location;    
}
}
?>

这是我的应用程序控制器页面:\ applications \ controller \ index

<?php
namespace applications\controllers;

use core\configuration\configloader as config;

class index extends \core\controller\controlmaster{
public $config;

public function __construct(){
    $this->config = new config;
    $this->config->_parsePHP("j3mp_setting.php");
    parent::_setModelBase($this->config->settings['app_model_base']);   // Error doesn't appear when i comment this function
    echo "This is main page and this is config for model app base : {$this->config->settings['base_url']}"; 
}
}
?>

这是核心\ configuration \ configloader:

<?php
namespace core\configuration;
class configloader{
//Contains setting informations
public $inisettings;
public $settings;

public function _parseINI($file,$section){
    $section = empty($section) ? false : true;
    $file = __DIR__.DIRECTORY_SEPARATOR.$file;
    if(file_exists($file)){
        $parse = parse_ini_file($file,$section);
        $this->inisettings = $parse;
    }else{
        throw new core\errorhandler\exception("File {$file} is not found in our system. Please contact administrator for details.","configloader");
    }
}

public function _parsePHP($file){
    $file = __DIR__.DIRECTORY_SEPARATOR.$file;
    if(file_exists($file)){
        $settings = array();
        include($file);
        $this->settings = $settings;    
    }else{
        throw new core\errorhandler\exception("File {$file} is not found in our system. Please contact administrator for details.","configloader");
    }
}
}
?>

当我评论&#34; parent :: _ setModelBase(...)&#34;代码,错误消失,浏览器成功打印&#34;这是主页面,这是模型应用程序库的配置:http://iosv3.net/&#34;。我认为错误来自\ core \ controller \ controlmaster,但我不知道如何解决这个问题?我总是尝试编辑文件(\ core \ controller \ controlmaster)但是没有发生...如果发生错误,消息(&#34;这是主页......&#34;)没有来你能告诉我错误来自哪里?感谢...

0 个答案:

没有答案