1. Go to this page and download the library: Download ingenerator/kohana-view library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace View\Layout;
/**
* @property-read ViewModel $sidebar
*/
class ContentWithSidebarLayoutView extends Ingenerator\KohanaView\ViewModel\PageLayout\AbstractIntermediateLayoutView
{
public function __construct(SitePageTemplateView $page, ViewModel $sidebar)
{
parent::__construct($page);
$this->sidebar = $sidebar;
}
protected function var_sidebar()
{
return $this->sidebar;
}
}
namespace View\Layout;
class SidebarView extends AbstractViewModel
{
// Whatever you want it to show
}
namespace View\Pages;
/**
* @property-read View\Layout\SitePageTemplateView $page
* @property-read string $name
*/
class HelloWorldView extends Ingenerator\KohanaView\ViewModel\PageLayout\AbstractNestedChildView
{
protected $variables = [
'name' => NULL
];
protected function var_page()
{
// If you want to make this available to set things from the view : it's not
//application/views/pages/hello_world.php
/**
* @var \View\Pages\HelloWorldView $view
* @var \Ingenerator\KohanaView\Renderer\HTMLRenderer $renderer
*/
// You can do this here if you want to keep templatey-type stuff together
// Or in your view model at display time if it's a bit more involved
$view->page->setTitle('Hello World');
class Controller_Welcome extends Controller // Look, extend any controller! No more Controller_Template!
{
public function action_index()
{
// You probably want to put your views into the dependency container too
$content = new HelloWorldView(
new ContentWithSidebarLayoutView(
new SitePageTemplateView(),
new SidebarView()
)
);
$content->display(['name' => $this->request->query('name')]);
$renderer = $this->dependencies->get('kohanaview.renderer.page_layout');
/** @var \Ingenerator\KohanaView\Renderer\PageLayoutRenderer $renderer */
$this->response->body($renderer->render($content));
}
}
class View_That_Does_Work {
protected $variables = [
'user_email' => ''
];
protected function var_user_activity()
{
$activity = [];
foreach ($this->database->loadActivityForUser($this->user_email) as $activity) {
$activity[] = (string) $activity;
}
$this->variables['user_activity'] = $activity;
// Future usage of $view->user_activity will now get the value cached in the variables array without calling
// this method again.
return $activity;
}
}
class View_Container {
protected $variables = [
'users' => [],
];
public function __construct(View_User_FaceWidget $face_widget)
{
$this->face_widget = $face_widget;
}
protected function var_face_widget()
{
return $this->face_widget;
}
}