Comments (12)
For example to include view from template folder, one can directly use util. function.
For templates specifically.....I'm kinda not a fan of the implementation that flight has cause it's.....super limited. I would HIGHLY recommend something like Latte (my fav) or Twig if you want a real hardcore (and secure!) templating framework. Since Flight is really just a basic router "with some flare" adding a full templating system is overkill.
As for the other things you mention I believe what you're after is containerization which Flight has built in (in a weird way). In most frameworks you do something like $db = Container::get('db');
so you can share the same instance of db. How you would implement the container in flight is just like how you did it for your db instance with Flight::db(); You would just do the same with Flight::session(), Flight::cache(), etc.
If you go the object oriented way, you'd just do $Engine->cache()
for instance after you register it.
from core.
Latte is amazing!
https://latte.nette.org/en/
from core.
Some helpful utility functions could be —
- CSRF token generator
- Caching page
- Cookie
- Session
- Validation
Few of the helpers I've extended from third-party packages.
Sessions Management Utilities
function set_session_value($key, $value)
{
global $session;
return $session->set($key, $value);
}
function pull_session_value($key)
{
global $session;
return $session->pull($key);
}
function remove_session_value($key)
{
global $session;
return $session->remove($key);
}
function destroy_session()
{
global $session;
return $session->clear();
}
Package used: josantonius/session
use Josantonius\Session\Session;
$session = new Session();
$session->start([
'name' => "my_app",
'cookie_httponly' => true,
]);
Likewise, I am currently using DB (using MeekroDB) —
function register_db_instance()
{
// MeekroDB for MySQL-PDO Connection
Flight::register('db', 'MeekroDB', [
$_ENV['DB_HOST'],
$_ENV['DB_USER'],
$_ENV['DB_PASSWORD'],
$_ENV['DB_NAME'],
null,
'utf8',
]);
}
And, later defined helper functions for my DB-usages as:
function get_item_from_db($table, $slug)
{
$db = Flight::db();
$query = sprintf("SELECT * FROM %s WHERE slug=%%s;", $table);
$item = $db->queryFirstRow($query, $slug);
return $item;
}
from core.
I agree, I use it in ALL my projects. Super intuitive, fast, and feels good!
from core.
What do you think about a dependency injection container?
Flight technically already has one. When you do Flight::register()
and then Flight::myMethod()
that's technically a container.
from core.
Maybe an example might help? I think you could still do Flight::db()
in your controller.
from core.
Yeah I see your point. We have a discussion going on about that currently here.
The thing with PSR7 is that just by having it, doesn't mean it will work with Swoole and such. It is a step in the right direction though. The thing that concerns me is that there are some core pieces that will need to be disassembled and reconnected a different way in order for us to truly be compatible with async frameworks. Thank goodness for the 100% unit test coverage but I'm confident there's use cases of the core that aren't covered in those unit tests and we'll break backwards compatibility for folks. It's a complex situation :)
As for leaving Fat-Free, I haven't left Fat-Free. Still have a few projects where Fat-Free is the core of the project. There's just a few things that I've wanted to change about Fat-Free and it's hard to make changes on a project that's not well unit tested and also doesn't have the proper licensing in place. There's also a few fundamental flaws in place that are kind of annoying to work around. But overall I'm very thankful for Fat-Free. It really helped me get do understand centralized routing and the importance of good code structure (given loose guidelines). I also liked that the codebase was simple enough that I could dive in and try to figure things out. Flight though I feel takes that to the next level. There were a few major features I felt were lacking and I feel now with where Flight is (with the active record libary now) it is a framework I can do a lot of good damage with on projects!
from core.
What do you think about a dependency injection container?
from core.
yes but what if a controller uses composition over inheritance and receives its dependency. I don't know how many ways there are to solve this problem but with DI-Container it would be solved
from core.
This is an old topic, at the time I was against it as I saw psr7 an unnecessary overhead that other frameworks were using. However, an adapter for flight would allow it to easily use swoole or road runner along with the many psr7 compliant middlewares out there. @n0nag0n why did you stop using fatfree framework?
from core.
Related Issues (20)
- Compatibility issue with PHP 8.1-8.2 HOT 7
- Route preg_match() error HOT 1
- display_errors does not work with flight HOT 4
- route view rendered after redirect HOT 7
- Argument #1 ($ex) must be of type Exception, TypeError given HOT 2
- Cors in Framework HOT 5
- describing routes HOT 3
- Slashes In Routes HOT 2
- Website outdated version HOT 1
- I make a new framework ‘Alight’, can anyone try it and give me some feedback? HOT 1
- Flushing buffer results in Response->write() error HOT 1
- Migrate to Flight 2 HOT 1
- Future of the Flight Micro Framework HOT 19
- Naming routes - help for navigation HOT 4
- Example projects - What would that look like ? HOT 14
- Possible integration with Roadrunner and Swoole. HOT 2
- Possible way to generate OpenAPI specification on the fly. HOT 1
- Possible deployment on AWS Lambda. HOT 1
- Documentation on how to Docker-ize FlightPHP application. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core.