flightphp / core

An extensible micro-framework for PHP
https://docs.flightphp.com
MIT License
2.61k stars 408 forks source link

Better way to use framework #256

Closed stufa00 closed 8 years ago

stufa00 commented 8 years ago

Hey Mike,

I think a better way to use your framework is through a singleton function as follows. It's better than static class because then you can easily set (global) variables without the need for any separate get(), set(), has() functions.

function app() { static $app; if (!$app) $app = new flight\Engine(); return $app; }

app()->config = require 'config.php'; app()->db = new PDO('mysql:host=localhost;dnbname=test','user','pass'); .. app()->start();

Thanks for the great framework.

jimlei commented 8 years ago

Using Flight like this is referenced in the documentation

Framework Instance

Instead of running Flight as a global static class, you can optionally run it as an object instance.

http://flightphp.com/learn#footer