classes/controller/base.php:
----------
abstract class Controller_Base extends Controller_Template
{
public $template = 'template.smarty';
public function before()
{
parent::before();
}
public function after($response)
{
parent::after($response);
// Set ViewModel
$active = Request::active();
$viewmodel = $active->route->segments[0] .'/'. $active->route->segments[1];
View::set_global('content', ViewModel::forge($viewmodel));
}
}
----------
classes/controller/home.php:
----------
class Controller_Home extends Controller_Base
{
public function before()
{
parent::before();
}
public function action_index()
{
}
}
----------
classes/views/home/index.php:
----------
class View_Home_Index extends ViewModel
{
protected $_view = 'home/index.smarty';
public function before($data = null)
{
parent::before();
View::set_global('title', 'Hello world') ;
}
public function view()
{
$this->hello = 'Hello world';
}
}
----------
views/template.tpl:
----------
<!DOCTYPE html>
<html lang="en">
<head>
<title>{$title}</title>
</head>
<body>
{$content}
</body>
</html>
----------
views/home/index.tpl:
----------
{$hello}
----------
Many thanks,public function after($response)
{
// Set ViewModel
$active = Request::active();
$viewmodel = $active->route->segments[0] .'/'. $active->route->segments[1];
View::set_global('content', ViewModel::forge($viewmodel));
return parent::after($response);
}
It looks like you're new here. If you want to get involved, click one of these buttons!