1. Go to this page and download the library: Download iamshobe/flight library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
iamshobe / flight example snippets
namespace App\Views;
use \Flight\Views\View;
class Index extends View {
public function __invoke($vars) {
$json = json_encode(["hello" => $vars["hello"]]);
return $this->response($json, 200, ["content-type" => "application/json"]);
}
}
namespace App\Views;
use \Flight\Views\View;
class File extends View {
public function __invoke($vars) {
return $this->page("index.phtml");
}
}
namespace App\URLS;
use \Flight\URLS\URL;
class URLS {
function __invoke()
{
return [
new URL("^lol$", new \App\Views\File()),
new URL("^(?P<hello>.*)$", new \App\Views\Index())
];
}
}
e_once "./urls.php";
(new \Flight\Dispatcher(__DIR__, (new App\URLS\URLS())()))->dispatch();
namespace App\URLS;
use \Flight\URLS\URL;
class URLS2 {
function __invoke()
{
return [
// this will cause a prefix of http://example.com/lol....
new URL("^lol$", new \Flight\URLS\IncludeURLS((new \App\URLS\URLS())()))
];
}
}
namespace App\URLS;
use \Flight\URLS\URL;
class URLS {
function __invoke()
{
return [
// this will cause a url of http://example.com/lollol
new URL("^lol$", new \App\Views\File(), ["GET"]),
// this will cause a prefix of http://example.com/lol(.*)
// where everything in brackets will be passed to hello var array.
new URL("^(?P<hello>.*)$", new \App\Views\Index(). ["POST"])
];
}
}
apacheconfig
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteRule .* ./index.php