我已經保存到其對應的子目錄,在我的項目的應用程序/控制器目錄,加載控制器
EX控制器。
1.App/Controller/Common for header,footer,home,top_column,left column。
2.App/Controller/User for user,user-permisson。
等等等等。
App/Controller目錄保持不變,但每個控制器都有不同的子文件夾。爲了加載這些控制器,我想我首先需要展開路徑,擺脫子目錄名稱,然後在App/Controller的目錄中查找控制器,如果發現實例化它。
下面這是代碼的草稿我的工作檢查,如果上面說的作品或不
<?php
$path = 'common/Left_Column';
$result = explode("/", $path);
array_shift($result);
$result = implode("/", $result);
echo $result; // Displays Left_Column
echo '<br>';
$file = 'App/Controller/' . $path . '.php';
echo $file; // Displays App/Controller/common/Left_Column.php
echo '<br>';
$class = $result;
echo $class; // Displays Left_Column
$controller = new $class(); // Error: Fatal error: Class 'Left_Column' not found in C:\xampp\htdocs\w3school\index.php on line 19
它的工作,但最後一行,我嘗試實例化類我得到這個錯誤「錯誤:致命錯誤:在第19行的C:\ xampp \ htdocs \ w3school \ index.php中找不到類「Left_Column」。
爲什麼找不到類Left_Column?
編輯:作爲coulmn拼寫的列,現在改變。
jeeeez,......這樣一個愚蠢的錯誤.....謝謝。 – RnD