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.
Feels like most of what's going on in here is resolved in the other discussion or will be addressed at some point (real containers). As for the view parts, Latte may be the best choice as it's best to keep your templates as "dumb" as possible without injection globals or outside services into your templates.
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.
FYI, a DIC is now part of Flight https://docs.flightphp.com/learn/dependency-injection-container
from core.
Related Issues (20)
- Handling of URLs with encoded slashes (/)
- Have URL parameters available when setting streaming headers HOT 2
- Upgrade from 3.2.0 to 3.6.1 breaks Flight::json ? HOT 2
- [Docs > Routing] Method Routing HOT 6
- [Refactor] Flight::get() need to be renamed HOT 2
- [Views] register method : no autocomplete / intelsense HOT 3
- get_input_data HOT 3
- Comments before begin php tag returns json with garbage HOT 4
- FYI, minor bug with streamWithHeaders() HOT 11
- Multiple renders keeps the previous state When I render multiple views as components, they keep the state of previous arguments passed to them instead of reinitialize with default value each render.
- Inject Middleware constructor arguments using the DI Container HOT 4
- Proposal of compact syntax for Flight::route HOT 7
- View class steroids 🙌🏽 HOT 1
- How to stop the request process when there is an issue in the Middleware? HOT 8
- Named Parameters Are Actually In Order... HOT 7
- Simplify PHP version constraint HOT 4
- Flight::group lacks nesting support for organizing routes hierarchically. Adding this feature will enhance route management flexibility. HOT 3
- Wrong request method response HOT 2
- Including version number of Flight in Flight.php root file HOT 3
- How to show custom page for 500 error? HOT 2
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.