43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace generic\core;
|
|
|
|
|
|
abstract class i_view{
|
|
|
|
/* (1) Renders the view
|
|
*
|
|
---------------------------------------------------------*/
|
|
public function render(){
|
|
|
|
/* (1) Get path information (child class)
|
|
---------------------------------------------------------*/
|
|
/* (1) Get child class */
|
|
$child_class = str_replace('\\', '/', get_class(debug_backtrace()[0]['object']));
|
|
|
|
/* (2) Extract root DIR */
|
|
$root_path = __BUILD__.'/generic/'.dirname($child_class);
|
|
|
|
/* (3) Extract file name */
|
|
$base_path = basename($child_class).'.twig';
|
|
|
|
|
|
/* (2) Setup
|
|
---------------------------------------------------------*/
|
|
/* (1) Initialize twig */
|
|
$loader = new \Twig_Loader_Filesystem($root_path);
|
|
$twig = new \Twig_Environment($loader, [
|
|
'debug' => true,
|
|
'cache' => false,
|
|
'auto_reload' => true
|
|
]);
|
|
|
|
|
|
/* (3) Build the view and return it back
|
|
---------------------------------------------------------*/
|
|
/* (1) Render and return the view */
|
|
return $twig->render($base_path, [ 'core' => $this ]);
|
|
|
|
}
|
|
|
|
} |