Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Symfony2 equivalent of components in Symfony1?

Tags:

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?

like image 916
jihi Avatar asked May 22 '11 11:05

jihi


People also ask

What is Symfony component?

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.

What is Symfony Console component?

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.

Which is better Laravel or Symfony?

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.

What is dependency injection in Symfony?

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.


1 Answers

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.

like image 173
jihi Avatar answered Sep 20 '22 08:09

jihi