PHP自動加載報錯找不到原因,求大佬幫忙看看
問題描述
<?phpnamespace frameworkcore;class Framework{ //在構造方法中初始化 public function __construct() {$this->autoload();$this->initMCA();$this->dispatch(); } //注冊自動加載 public function autoload() {//說明:如果一個函數的參數是回調函數,就直接寫函數的名字//如果函數的參數是一個對象的方法的話,需要傳遞數組進去,參數1:對象;參數2:對象的方法spl_autoload_register(array($this,"autoloader")); } //自動加載執行的函數 public function autoloader($className) {echo '我們需要:'.$className.'<br>';//針對第三方的類,做一個特例處理if($className=='Smarty'){ require_once './framework/vendor/smarty/Smarty.class.php'; return;}//1. 先將帶有命名空間的類,分隔開$arr = explode('', $className); //2. 根據第一個元素確定加載的根目錄if($arr[0] == 'framework'){ $basic_path = './';}else{ $basic_path = './application/';}//3. 確定application、framwork里面的子目錄$sub_path = str_replace('', '/', $className); //4. 確定文件名//確定后綴:類文件的后綴:.class.php,接口文件的后綴是:.interface.php//frameworkdaoI_DAO,判斷最后元素是否是I_開頭if(substr($arr[count($arr)-1], 0,2)=='I_'){ //說明是接口文件 $fix = '.interface.php';}else{ $fix = '.class.php';}$class_file = $basic_path.$sub_path.$fix; //5. 加載類//如果不是按照我們的命名空間的規則定義的,說明不是我們需要加載的類,不用加載if(file_exists($class_file)){ require_once $class_file;} } //確定mca public function initMCA() {//前臺還是后臺?$m = isset($_GET['m'])?$_GET['m']:'home';define('MODULE', $m);//訪問哪個控制器$c = isset($_GET['c'])?$_GET['c']:'Index';define('CONTROLLER', $c);//訪問控制器的哪個操作$a = isset($_GET['a'])?$_GET['a']:'indexAction';define('ACTION', $a); }//實例化對象,調用方法 public function dispatch() {$controller_name = MODULE.'controller'.CONTROLLER.'Controller';//先加載控制器類,再實例化對象$controller = new $controller_name;//調用控制器的方法$a = ACTION;$controller -> $a(); }}
問題解答
回答1:你把smarty重新下載看看,先看看你項目中的smart中是否有sysplugins文件夾和plugins文件夾沒有就考進去。
![css3 - [CSS] 動畫效果 3D翻轉bug](http://www.aoyou183.cn/attached/image/news/202304/110831f073.png)