Подскажите, пожалуйста, как лучше реализовать кеширование частей страницы в MVC? Лучше это реализовать в контроллере или модели и как об этом сообщить View?
Если можно, приведите простой пример.
//запуск системы
MainController :: run();
class MainController{
private static $_registry;
private function __construct(){
}
//start
static function run(){
$mainController = new MainController();
$mainController->handleRequest(self::$_registry);
}
//Получение запроса, выбирает файл-класс-метод обработки запроса -
//передача полномочий по обработке запроса объекту CommandResolver
public function handleRequest(){
$cmd = $this->_response->getCommand(self::$_registry);//запуск объекта типа Command
//...
$cmd->doExecute(self::$_registry); //исполнение опред.команды(контроллер страницы) + вывод на экран
}
}
//родитель контроллеров
abstract class Command
{
protected $_registry;
public function __construct(Registry $registry, $adaptee=self::ADAPTER_TYPE)
{
$this->_registry = $registry;
}
abstract function doExecute();
}
//контроллер страницы
class AdminSystemStructurePagesCommand extends Command{
public function __construct(Registry $registry, $adaptee=self::ADAPTER_TYPE) {
parent::__construct($registry);
}
public function doExecute()
{
$template = PAGE_PATH . "view/theme/" . $this->theme_admin . "/template/" . $this->typetpl . "/system/structure/pages";
$this->parts = array(
'common/blocks/header'
);
$this->_params = array(
'pages'=>$pages,
'title'=>$title
);
$this->setPartsVarsToTpl();
$this->_view->render($template, $this->_params);
}
//....
}
//общий шаблон страницы, тоже только основное
<?php print $header?>
<body>
<div class="container_12">
<div class="grid_12 header-repeat">
<div id="branding"><?php print $menu?></div>
<div class="clear"></div>
</div>
</div>
<?php print $content?>
<div id="site_info">
<?php print $footer?>
</div>
</body>
</html>
//Ну и $header, $menu, $content,$footer - контроллеры заполняют соответствующими шаблонами.