Commit
This commit is contained in:
parent
550a64f57e
commit
68006814cc
@ -8,6 +8,7 @@ class App
|
|||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Grab model
|
||||||
public function model(string $model): object
|
public function model(string $model): object
|
||||||
{
|
{
|
||||||
// Require model file
|
// Require model file
|
||||||
@ -16,6 +17,7 @@ class App
|
|||||||
return new $model();
|
return new $model();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Render given view
|
||||||
public function view(string $view, array $data = []): void
|
public function view(string $view, array $data = []): void
|
||||||
{
|
{
|
||||||
// Import variables into the current symbol table from an array
|
// Import variables into the current symbol table from an array
|
||||||
@ -23,4 +25,14 @@ class App
|
|||||||
// Require view file
|
// Require view file
|
||||||
require __DIR__ . '/../view/' . $view . '.php';
|
require __DIR__ . '/../view/' . $view . '.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Turn data array into JSON response
|
||||||
|
public function api(array $data, int $status_code = 200): void
|
||||||
|
{
|
||||||
|
// Set headers
|
||||||
|
http_response_code($status_code);
|
||||||
|
header('Content-type: application/json');
|
||||||
|
// Convert and respond with data
|
||||||
|
echo json_encode($data);
|
||||||
|
}
|
||||||
}
|
}
|
6
public/api/simulator.php
Normal file
6
public/api/simulator.php
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
$app = require '../../app/inc.php';
|
||||||
|
|
||||||
|
$app->api([
|
||||||
|
"msg" => "Hello World!"
|
||||||
|
]);
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
$app = require("../app/inc.php");
|
$app = require '../app/inc.php';
|
||||||
|
|
||||||
$model = $app->model('Index');
|
$model = $app->model('Index');
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
$app = require("../app/inc.php");
|
$app = require '../app/inc.php';
|
||||||
|
|
||||||
$app->view('template/header', ["title" => "Logg inn"]);
|
$app->view('template/header', ["title" => "Logg inn"]);
|
||||||
$app->view('login');
|
$app->view('login');
|
||||||
|
Reference in New Issue
Block a user