Получаю ошибку 500. Вот логи:
[warn] [pid 20994] sapi_apache2.c(362): PHP Warning: require(/home/c/cs27399/public_html\\config\\routes.php): failed to open stream: No such file or directory in /home/c/cs27399/public_html/core/Router.php on line 10
[error] [pid 20994] sapi_apache2.c(362): PHP Fatal error: require(): Failed opening required '/home/c/cs27399/public_html\\config\\routes.php' (include_path='.:/opt/php71/share/pear') in /home/c/cs27399/public_html/core/Router.php on line 10
Я использую константу define('ROOT', dirname(__FILE__));
Файл routes.php
return [
'api/auth/signin' => [
'controller' => 'user',
'action' => 'signin'
]
];
Router.php
class Router
{
protected $routes = [];
protected $params = [];
public function __construct()
{
$this->routes = require ROOT . '\config\routes.php';
}
private function getURI()
{
if (!empty($_SERVER['REQUEST_URI'])) {
return trim($_SERVER['REDIRECT_URL'], '/');
}
}
public function match($uri)
{
$routeURI = preg_replace('/\d{1,}/','\d',$uri);
if(isset($this->routes[$routeURI])){
$this->params = $this->routes[$routeURI];
return true;
};
return false;
}
public function run()
{
$uri = $this->getURI();
if ($this->match($uri)) {
$controllerFileName = ucfirst($this->params['controller']);
$controllerFile = ROOT . '\\controllers\\' . $controllerFileName . '.php';
if (is_file($controllerFile)) {
require_once $controllerFile;
$classNameController = $controllerFileName.'Controller';
$controller = new $classNameController($this->params); //Отправляем данные из routing в контроллер и создаем обьект с controller'ом
$actionName = $this->params['action'].'Action';
$controller->$actionName();
}
} else {
require_once ROOT .'\\index.html';
// $controller = new ErrorController(['controller' => 'error']);
// $actionName = 'error404Action';
// $controller->$actionName();
}
}
}