Let's create a content module that will handle both static and dynamic content:
First enable the module:
modules/application/bootstrap.php
Kohana::modules(array( . . 'content' => MODPATH . 'content', // Content module . . ));
Second, create the master template controller:
modules/content/classes/controller/base/template.php
template_name = Kohana::$config->load('content.template.name');
$this->template = 'template/'.$this->template_name.'/index';
parent::before();
if ($this->auto_render) {
$this->template->title = '';
$this->template->content = '';
$this->template->styles = array();
$this->template->scripts = array();
}
}
public function after() {
if ($this->auto_render) {
$styles = Kohana::$config->load('content.template.style');
$scripts = Kohana::$config->load('content.template.script');
$this->template->styles = array_merge( $this->template->styles, $styles );
$this->template->scripts = array_merge( $this->template->scripts, $scripts );
}
parent::after();;
}
}
Define routes to call the content module:
modules/content/init.php
<?php defined('SYSPATH') or die('No direct script access.');
/**
* Routes for Content
*
* @package……Content
* @category…..Routing
* @author…….Mauricio Otta
* @copyright….PortNumber53.com
*/
if (! Route::$cache) {
Route::set('homepage-content', '(<language–>"/)()',
array(
'language' => '(pt-br)',
'nothing' => '',
))
->defaults(array(
'controller' => 'content',
'action' => 'homepage',
));
Route::set('static-content', '(/).html',
array(
'language' => '(pt-br)',
'path' => '[a-zA-Z0-9_/\.=\-]+',
))
->defaults(array(
'controller' => 'content',
'action' => 'static',
));
}
Define the base content controller
response->body('Controller_Base_Content::index();
');
}
public function action_homepage() {
$this->template->content = 'homepage';
}
public function action_static() {
$path = $this->request->param('path');
if ($filepath = Kohana::find_file('views', 'content/static/' . $path . '.html')) {
$filepath = 'content/static/' . $path . '.html';
//$this->template->content = 'static here'.$filepath;
$content = new Model_Content();
$latest_content = $content->get_last_posts(10);
View::bind_global('latest_content', $latest_content);
$this->template->content = View::factory($filepath, array(
'latest_content' => $latest_content,
))->render();
switch ($path) {
case 'privacy-policy': $title = 'Privacy Policy'; break;
default:
$title = 'unknown: ' . $path;
}
$this->template->facebook_og['og:title'] = $title;
View::set_global('title', $title);
} else {
$this->action_dynamic();
}
}
public function action_dynamic() {
$path = '/'.$this->request->param('path', '');
$content = new Model_Content();
$latest_content = $content->get_last_posts(10);
View::bind_global('latest_content', $latest_content);
$post = $content->get_post_by_url($path);
if ($post && $latest_content) {
$this->template->content = View::factory('content/main', array(
'latest_content' => $latest_content,
'content' => $post,
)
);
} else {
$this->template->content = View::factory('content/main', array(
'content' => array(
'type' => Content::TYPE_UNKNOWN,
'description' => 'Content not found',
),
)
);
}
}
}
Define the content controller (~/modules/content/classes/controller/content.php):
<?php
class Controller_Content extends Controller_Base_Content { }
?>
Store some configuration values for the module (~/modules/content/config/content.php):
array( 'name' => 'default', 'style' => array( 'media/css/3-column-px.css' => 'screen', 'media/css/screen.css' => 'screen, projection', 'media/css/print.css' => 'print', 'template/default/css/style.css' => 'screen', ), 'script' => array( 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js', ), ), );
……………………………………………………………

Deprecated: printf(): Passing null to parameter #1 ($format) of type string is deprecated in /var/www/vhosts/blog.portnumber53.com/html/wp-content/themes/mantra/includes/theme-comments.php on line 86