From 11d488fd785a4514ad35c15e9f8a82781c56a452 Mon Sep 17 00:00:00 2001 From: Krivchikov Dmitry Date: Thu, 3 Apr 2014 13:32:49 +0400 Subject: [PATCH] FIX autoload --- ground/app.php | 4 ++-- public/index.php | 24 +++++++----------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/ground/app.php b/ground/app.php index 41bb57a..b673594 100644 --- a/ground/app.php +++ b/ground/app.php @@ -81,10 +81,10 @@ class App } } - public static function error404() + public static function error404($message = '') { header("HTTP/1.0 404 Not Found"); - die('404'); + die('Error 404 '.$message); } public static function redirect($url) diff --git a/public/index.php b/public/index.php index d14dcd7..3d17759 100644 --- a/public/index.php +++ b/public/index.php @@ -2,27 +2,17 @@ // Поехали! -$dirname = dirname(__FILE__) . '/../'; - -foreach (glob($dirname . "ground/classes/*.php") as $filename) +function __autoload($className) { - include_once $filename; -} - -spl_autoload_register('autoload'); - -function autoload($className) -{ - $fileName = dirname(__FILE__) . '/../ground/controllers/' . $className . '.php'; + $dirname = dirname(__FILE__) . '/../'; + $fileName = strpos($className, 'Controller') ? $dirname . 'ground/controllers/' . $className . '.php' : $dirname . 'ground/classes/' . strtolower($className) . '.php'; if (file_exists($fileName)) include $fileName; else - App::error404 (); + App::error404 ('load class '.$className); } -include_once $dirname . 'ground/app.php'; -include_once $dirname . 'ground/config.php'; +include_once dirname(__FILE__) . '/../ground/app.php'; +include_once dirname(__FILE__) . '/../ground/config.php'; -App::run($config); - -// И немного магии +App::run($config); \ No newline at end of file