Custom error 404 page.

This commit is contained in:
Krivchikov Dmitry 2014-11-16 10:31:42 +03:00
parent 3482540b5e
commit b545fac89f
4 changed files with 35 additions and 1 deletions

View File

@ -109,7 +109,8 @@ class App
public static function error404($message = '') public static function error404($message = '')
{ {
header("HTTP/1.0 404 Not Found"); header("HTTP/1.0 404 Not Found");
die($message ? $message : '404 - Not Found'); PageController::action404($message ? $message : '404 - Not Found');
die;
} }
// Пытаемся восстановить пользователя из сессии // Пытаемся восстановить пользователя из сессии

View File

@ -60,6 +60,12 @@ class PageController extends Controller
self::addStyle('/css/fotorama.css'); self::addStyle('/css/fotorama.css');
$point = Point::model()->getByPK($pointId); $point = Point::model()->getByPK($pointId);
if (!isset($point->id))
{
App::error404();
}
$point->descriptionHtml = nl2br($point->description); $point->descriptionHtml = nl2br($point->description);
$point->name = htmlspecialchars($point->name); $point->name = htmlspecialchars($point->name);
App::setConfig('title', $point->name. ' - wikipoints.ru'); App::setConfig('title', $point->name. ' - wikipoints.ru');
@ -91,4 +97,10 @@ class PageController extends Controller
} }
} }
static function action404($message)
{
self::renderPartial('error404.php', array(
'point' => Point::model()->getRandom(),
));
}
} }

19
ground/views/error404.php Normal file
View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>Ошибка 404 - страница не найдена!</title>
</head>
<body>
<h1>Ошибка 404 - страница не найдена!</h1>
<hr/>
<br/>
<noindex>
<div style="text-align: center;">
<h2>Не беда! Возможно вас заинтересует точка «<?= $point->name ?>»?</h2>
<a href="/page/point/id/<?= $point->id ?>">
<img src="<?= $point->getImg() ?>" style="max-width: 400px; margin: 0 20px 10px 0;" />
</a>
</div>
</noindex>
</body>
</html>

View File

@ -1,6 +1,8 @@
AddDefaultCharset utf-8 AddDefaultCharset utf-8
RewriteEngine On RewriteEngine On
ErrorDocument 404 /page/404/
RewriteBase / RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-l RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-f