examples
This commit is contained in:
parent
56891bda09
commit
f588a293ed
@ -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
24
app/api/ExampleApi.php
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
18
app/controllers/ExampleController.php
Normal file
18
app/controllers/ExampleController.php
Normal 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';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Controller{
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user