Created
March 13, 2011 10:06
-
-
Save paulchubatyy/868001 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Вішаємось на післяроутингу | |
// це викличе нашу функцію коли роутинг закінчиться | |
Event::add('system.post_routing' ,'call_fallback_page'); | |
function call_fallback_page() | |
{ | |
// визначаємо чи наразі визначений контроллер | |
if (Router::$controller === NULL) { | |
// контроллера нема, якраз наш випадок! | |
Router::$controller = 'page'; | |
// встановлюємо наш контроллер ^ і метод, якмй показуватиме статичну сторінку | |
Router::$method = 'show'; | |
// знаходимо шлях до контроллера | |
Router::$controller_path = Kohana::find_file('controllers', 'page'); | |
} | |
} | |
// перший профіт! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Сторінки розмічені маркдауном | |
require Kohana::find_file('vendor', 'Markdown'); | |
// Власне контроллер. Я використовую Template_Controller свого приготування, | |
// не забудьте поміняти свого парента | |
class Page_Controller extends Website_Controller { | |
public function show() | |
{ | |
$page = ORM::factory('page', Router::$current_uri;); | |
// orm модель має перевизначений метод unique_id() | |
if ($page->id > 0) { | |
//сторінка знайдена! | |
//змінні как бе намєкають нам на правильну SEO оптимізацію | |
$this->template->keywords = $page->keywords; | |
$this->template->description = $page->description; | |
$this->template->content = new View('page'); | |
$this->template->content->title = $page->title; | |
$this->template->content->text = Markdown($page->body); | |
$this->template->content->modified = $page->modified; | |
} else { | |
// ніц не знайшли, показуємо 404-ту помилку. | |
Kohana::instance()->show_404(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment