Zrobiłem to w ten sposób.
Stworzyłem Site_Controller, który tworzy stronę i dołącza narazie tylko Menu_Conntroller.
<?php
class Site_Controller extends Template_Controller {
public $template = 'base_page';
public function __construct()
{
parent::__construct();
$this->template->title = "Welcome to Kohana!";
$this->template->copyright = "Š Me, 2008";
// Look:
$menu = new Menu_Controller;
$this->template->menu = $menu->_getMenu();
}
?>
Po klasie Site_Controller dziedziczy klasa News_Controller, w przyszłości będzie dziedziczyć każda strona znajdująca się w content.
<?php
class News_Controller extends Site_Controller {
// const ALLOW_PRODUCTION = FALSE;
public $AutoRender = TRUE;
public $aContent;
public function __construct(){
parent::__construct();
/*if ($this->AutoRender == TRUE){
Event::add('system.post_controller', array($this, '_render'));
}*/
}
public function _render(){
if ($this->AutoRender == TRUE){
$this->template->render(TRUE);
}
}
public function index($iActive='all', $iSubactive = NULL){
$this->template->content = 'ddd';
//$this->_render();
//$this->_setContent($iActive, $iSubactive);
}
public function one($iSubactive){
Benchmark::start('benchmark1');
$this->_setContent('one', $iSubactive);
Benchmark::stop('benchmark1');
print_r(Benchmark
::get('benchmark1')); }
public function all(){
$this->_setContent('all', NULL);
}
private function _setContent($iActive, $iSubactive){
$mContent = new Content_Model;
if($iActive == 'one'){
$this->template->content = new View('Content');
$this->aContent = $mContent->getOneContent($iSubactive);
$this->template->content->id = $this->aContent['id'];
$this->template->content->title = $this->aContent['title'];
$this->template->content->content = $this->aContent['content'];
if($this->aContent['comments']['num'] > 0){
$this->template->content->numofComments = $this->aContent['comments']['num'];
$this->template->content->comments = $this->aContent['comments']['content'];
}
$this->template->content->form_comments = new View('form_comments');
$this->template->content->form_comments->id = $this->aContent['id'];
}elseif($iActive == 'all'){
$this->template->content = new View('all');
$this->aContent = $mContent->getAllContent();
$this->template->content->news = $this->aContent['news'];
$this->template->content->numofComments = $this->aContent['num_of_comments'];
}
}
public function add_comment($iSubactive){
$mForm = new Form_comment_Model;
if($mForm->receiveData()){
$this->_setContent('one', $iSubactive);
$this->template->form_comments->message = 'Dodano komentarz';
}else{
$this->_setContent('one', $iSubactive);
$this->template->form_comments->message = 'Wypełnij wszystkie pola w formularzu';
}
}
}
?>
Jeszcze Menu_Controller
<?php
class Menu_Controller extends Template_Controller {
public $template = 'menu';
function __construct() {
parent::__construct();
}
public function _getMenu(){
$menuModel = new Menu_Model;
$this->template->title = $menuModel->_getTitle();
$this->template->pages = $menuModel->_getPages();
$this->template->subpages = $menuModel->_getSubPages();
}
}
?>
Proszę o ocenę i czy dobrze myślę, ale wydaje mi się że tak.