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 * 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 // require model file
$path = $this->dir . '/model/' . $model . '.php'; $path = $this->dir . '/model/' . $model_name . '.php';
if (!file_exists($path)) if (!file_exists($path))
{ {
throw new Exception("Model does not exist"); throw new Exception("Model does not exist");
} }
require $path; require $path;
// instantiate model return new $model_name($this->database);
if (!$injection)
{
$injection = $this->database;
}
return new $model($injection);
} }
/** /**
* Render given view * 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'; $_path = $this->dir . '/view/' . $_view . '.php';
if (!file_exists($__PATH)) if (!file_exists($_path))
{ {
throw new Exception("View does not exist"); throw new Exception("View does not exist");
} }
// import variables into the current symbol table from an array // import variables into the current symbol table from an array
extract($__DATA); extract($_data);
require $__PATH; require $_path;
} }
/** /**