Slim-Website | Slim Framework website for GitHub Pages | Search Engine Optimization library
kandi X-RAY | Slim-Website Summary
kandi X-RAY | Slim-Website Summary
Slim Framework website for GitHub Pages
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Slim-Website
Slim-Website Key Features
Slim-Website Examples and Code Snippets
Community Discussions
Trending Discussions on Slim-Website
QUESTION
I'm using Slim, and php-di for the container, I've been trying to figure out how to autowire the dependencies without success.
I have App\Models\Planner.php
that I'd like to inject into App\Controllers\MealPlanner.php
, along with various other classes and models that are called by different endpoints/methods/actions.
Right now on Services.php, I'm creating 4 services 2 which will get passed to other classes, and 2 factories which are the Planner.php and MealPlanner.php which is called in the router on index.php.
Now that MealPlanner is defined as a service, it can be called directly i.e from $app->any('/mealplanner/{action}', \MealPlanner::class);
, if I remove the $app->set('MealPlanner', ...)
I'll get "Callable MealPlanner does not exist", why is it callable there without accessing the container?
Secondly, let's say I'd like to inject Fruits class onto MealPlanner along with the Planner.php, to do that I'd have to add a new service $container->set("Fruits", (){ return App\Models\Fruits.php(PDO $db, $UserId) })
then on MealPlanner service I'd have to pass the fruits container there, and then on MealPlanner controller it'd now be:
ANSWER
Answered 2019-Jul-28 at 07:35I've created a framework that marries Slim 4 and Eloquent ORM called Willow. Here's how I use PHP-DI:
QUESTION
I'm setting up slim router v4, and I'd like to be be able to dynamically call the controller methods, using the placeholder from the route.
I.e when a request is made to 'example.com/users/{action}', the router would call the method from Users.php controller automatically without me having to specify the routes manually.
Basically I'm trying to avoid manually adding over 100 group->get(...) when they're all under /user route.
...ANSWER
Answered 2019-Jul-25 at 22:22The way I would suggest doing this is having a single, catch all route with a placeholder. You can then set action to an invocable controller, and execute a method based on the route parameter.
Route:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Slim-Website
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page