This commit is contained in:
William 2022-05-25 13:57:05 +00:00
parent 258135cd81
commit 57d43a4fb4

View File

@ -32,42 +32,32 @@ class App
/**
* Grab model
*
* TODO: have a look to see if this might name conflict with anything and
* maybe also throw an exception if the model class is not found within the file
*/
public function model(string $model, mixed $injection = NULL): object
public function model(string $model_name): object
{
// require model file
$path = $this->dir . '/model/' . $model . '.php';
$path = $this->dir . '/model/' . $model_name . '.php';
if (!file_exists($path))
{
throw new Exception("Model does not exist");
}
require $path;
// instantiate model
if (!$injection)
{
$injection = $this->database;
}
return new $model($injection);
return new $model_name($this->database);
}
/**
* Render given view
*
* Reason for the funky names is to avoid name conflicts
*/
public function view(string $__VIEW, array $__DATA = []): void
public function view(string $_view, array $_data = []): void
{
$__PATH = $this->dir . '/view/' . $__VIEW . '.php';
if (!file_exists($__PATH))
$_path = $this->dir . '/view/' . $_view . '.php';
if (!file_exists($_path))
{
throw new Exception("View does not exist");
}
// import variables into the current symbol table from an array
extract($__DATA);
require $__PATH;
extract($_data);
require $_path;
}
/**