tags:

views:

360

answers:

2

Hi,

why should i use a component instead of an action that renders a partial?

If actions can render partials, when is better using components?

Give me light about it..

Javi

+1  A: 

components are used when you want to include some kind of block in different parts of the site (for example, a "Top 10 Sales" or something similar) - that requires some controller code to render. You include a component's output in another template of an action / partial / another component by using

include_component($module_name, $component_name, array('var1' => $var1));
an action is supposed to be called directly by the browser , so you can't include it's output in another template (without some kind of hack) Think of components as a reusable block of html that can get included anywhere, vs actions that are the whole page rendered and sent to the browser

matei
Thanks!, this is what i was looking for: "An action is supposed to be called directly by the browser , so you can't include it's output in another template (without some kind of hack)".But my question now is: what's your opinion about removing components and adding a way to include actions (in the same way as components) in the templates ?? I'm "thinking" in asking for that as a feature to make symfony more simple.
You would be asking for what already exists - components are *exactly* designed for including 'actions' in templates.
Raise
it's not a good ideea to remove the components, because they are a lightweight version of the actions (they don't go through the routing system, filters etc. so they are more efficient at their job)
matei
+1  A: 

partial is a 'template' that can be reused in any view pages. its simple & fast. all $data must be passed as parameter to the partial. imo, should be preferred if possible.

component is like a 'template with its own action' that can be reused in any view pages. more powerful, but slower compared to partial. use if you have partials that require business logic (i.e. action/controller)

http://www.symfony-project.org/book/1_0/07-Inside-the-View-Layer#chapter_07_code_fragments

koss