This commit is contained in:
xinatorus 2020-04-29 20:14:53 +02:00
parent 56891bda09
commit f588a293ed
4 changed files with 51 additions and 0 deletions

View File

@ -23,5 +23,9 @@ $router->post('/api/login', 'AuthApi@login');
$router->post('/api/HA', 'GoogleHome@response'); $router->post('/api/HA', 'GoogleHome@response');
// examples
$router->any('/api/example', 'ExampleApi@example');
$router->any('/example', 'ExampleController@index');
$router->any('/example/subpage', 'ExampleController@subpage');
$router->run($_SERVER['REQUEST_METHOD'], '/'.(isset($_GET['url']) ? $_GET['url'] : '')); $router->run($_SERVER['REQUEST_METHOD'], '/'.(isset($_GET['url']) ? $_GET['url'] : ''));

24
app/api/ExampleApi.php Normal file
View File

@ -0,0 +1,24 @@
<?php
class ExampleApi extends ApiController{
public function example(){
// if this function should be accessible only for logged users uncomment next line
// $this->requireAuth();
// if user is logged in, next lines will be processed
// otherwise script get terminated with 401 UNAUTHORIZED
// input data are stored in $this->input
// in this example we just copy input to response
$response = $this->input;
// this method returns response as json
$this->response($response);
// you can specify returned http code by second optional parameter
// default value is 200
// $this->response($response, $httpCode);
}
}

View File

@ -0,0 +1,18 @@
<?php
class ExampleController extends Controller{
public function index(){
echo 'example';
// TODO:
// - set view
// - process POST variables
// ...
}
public function subpage(){
echo 'subpage';
}
}

View File

@ -0,0 +1,5 @@
<?php
class Controller{
}