Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ErrorPage404 #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions application/controllers/controller_404.php

This file was deleted.

4 changes: 2 additions & 2 deletions application/controllers/controller_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ function action_index()
в коде значению — паролю. Такое решение не правильно с точки зрения безопасности.
Пароль должен храниться в базе данных в захешированном виде, но пока оставим как есть.
*/
if ( $_SESSION['admin'] == "12345" )
if ( isset($_SESSION['admin']) && $_SESSION['admin'] == "12345" )
{
$this->view->generate('admin_view.php', 'template_view.php');
}
else
{
session_destroy();
Route::ErrorPage404();
$this->ErrorPage404();
}

}
Expand Down
5 changes: 5 additions & 0 deletions application/core/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ function action_index()
{
// todo
}

function ErrorPage404()
{
$this->view->generate('404_view.php', 'template_view.php');
}
}
56 changes: 21 additions & 35 deletions application/core/route.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ static function start()
$controller_name = 'Controller_'.$controller_name;
$action_name = 'action_'.$action_name;

/*
echo "Model: $model_name <br>";
echo "Controller: $controller_name <br>";
echo "Action: $action_name <br>";
*/

// подцепляем файл с классом модели (файла модели может и не быть)

$model_file = strtolower($model_name).'.php';
Expand All @@ -54,39 +48,31 @@ static function start()
if(file_exists($controller_path))
{
include "application/controllers/".$controller_file;

// создаем контроллер
$controller = new $controller_name;
$action = $action_name;

if(method_exists($controller, $action))
{
// вызываем действие контроллера
$controller->$action();
}
else
{
// если файл контроллера не содержит требуемого класса или действия
$controller = new Controller;
$controller->ErrorPage404();
}

}
else
{
/*
правильно было бы кинуть здесь исключение,
но для упрощения сразу сделаем редирект на страницу 404
*/
Route::ErrorPage404();
}

// создаем контроллер
$controller = new $controller_name;
$action = $action_name;

if(method_exists($controller, $action))
{
// вызываем действие контроллера
$controller->$action();
}
else
{
// здесь также разумнее было бы кинуть исключение
Route::ErrorPage404();
// если файл контроллера отсутствует
$controller = new Controller;
$controller->ErrorPage404();
}

}

function ErrorPage404()
{
$host = 'http://'.$_SERVER['HTTP_HOST'].'/';
header('HTTP/1.1 404 Not Found');
header("Status: 404 Not Found");
header('Location:'.$host.'404');
}

}
5 changes: 5 additions & 0 deletions application/views/404_view.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<?php
header('HTTP/1.1 404 Not Found');
header("Status: 404 Not Found");
?>

<h1>404</h1>
<p>
<img src="/images/404.png">
Expand Down