In my Symfony2 application, I want to have a widget displayed on various pages. This can't just be defined by its template, it need to call the DB and go through the controller.
In Symfony1, I would create a component and include it. How can I do the same in Symfony2?
Symfony Components are decoupled libraries for PHP applications. Battle-tested in hundreds of thousands of projects and downloaded billions of times, they're the foundation of the most important PHP projects.
The Console component eases the creation of beautiful and testable command line interfaces. The Console component allows you to create command-line commands. Your console commands can be used for any recurring task, such as cronjobs, imports, or other batch jobs.
Both PHP Laravel and Symfony PHP are developed on MVC architecture, but in terms of component reusability and code modularity, Symfony has the edge over Laravel on this one. It structures the program in an organised fashion and becomes the perfect fit for larger and complex projects.
The Symfony DependencyInjection component provides a standard way to instantiate objects and handle dependency management in your PHP applications. The heart of the DependencyInjection component is a container which holds all the available services in the application.
I did some more research, and the simplest way I found was just this simple line in the template:
{% render 'MyBundle:MyController:myAction' %}
This outputs the result of the action, with the template specified by the action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With