We'll start by creating a public
function, called render
that accepts two arguments. The first is $view
, which is the name (or path) of the view you want to display, and the second is $layout
, which will define which layout we use to show the view. Layout will also have a default value, so that we can keep things simple, in order to handle the displaying of views. Add the following code to the lib/bones.php
file, right after the set
function:
public function set($index, $value) {
$this->vars[$index] = $value;
}
public function render($view, $layout = "layout") {
$this->content = ROOT. '/views/' . $view . '.php';
foreach ($this->vars as $key => $value) {
$$key = $value;
}
if (!$layout) {
include($this->content);
} else {
include(ROOT. '/views/' . $layout . '.php');
}
}