if ( is_readable($fileName) ) {
include strtolower($fileName);
} else {
echo "Не читается";
}
if ( is_readable( strtolower($fileName) ) ) {
include strtolower($fileName);
} else {
echo "Не читается";
}
<?php
use App\Core;
class Load {
public static function _init() {
spl_autoload_register(array(new self, 'autoload'));
}
public function autoload($className)
{
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strripos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= $className . '.php';
if ( file_exists($fileName) ) {
include strtolower($fileName);
} else {
echo "не читается";
}
}
}
Load::_init();
<?php
namespace App\Core;
use App\Controllers;
class Router
{
private static $uri;
private static function getController() {
$array['controller'] = 'index';
$array['method'] = 'mainMethod';
self::$uri = explode('/', $_SERVER['REQUEST_URI']);
if (!empty(self::$uri[1])) {
$array['controller'] = self::$uri[1];
}
if ( !empty(self::$uri[2]) ) {
$array['method'] = self::$uri[2];
}
return $array;
}
public static function start() {
$route = self::getController();
$method = $route['method'];
$controller = "app\\controllers\\" . $route['controller'];
$obj = '';
if (class_exists($controller) ) {
$obj = new $controller;
} else {
self::notFound();
}
if ( method_exists($obj, $method) ) {
$obj->$method();
} else {
self::notFound();
}
}
public static function notFound() {
header('HTTP/1.1 404 Not Found');
header("Status: 404 Not Found");
header('Location:/Error');
}
}
addNews()
и тд. Их нет в frontend`е.