This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » support » General discussion » Actions Class Corresponding To Global Layout (layout.php)
Actions Class Corresponding To Global Layout (layout.php) [message #103398] Mon, 02 August 2010 10:27 Go to next message
sharmil  is currently offline sharmil
Messages: 6
Registered: August 2010
Location: Mumbai, India
Junior Member
I am new to Symfony and MVC so I apologize in advance if my question in unclear or even ridiculous.

I am trying to find the right place to place some logic that would be apply to my global layout (layout.php)...similar to how logic in a module's actions apply to the corresponding module template.

Thanks in advance!
Re: Actions Class Corresponding To Global Layout (layout.php) [message #103399 is a reply to message #103398 ] Mon, 02 August 2010 10:36 Go to previous messageGo to next message
halfer  is currently offline halfer
Messages: 9535
Registered: January 2006
Location: West Midlands, UK
Faithful Member
If it's a particular block, I would use a component, or several. This is like a mini action that has its own logic and template, and can be output inside the layout. Its output can also be cached so as to speed up subsequent uses.


Remember Palestine
Re: Actions Class Corresponding To Global Layout (layout.php) [message #103402 is a reply to message #103399 ] Mon, 02 August 2010 11:08 Go to previous messageGo to next message
sharmil  is currently offline sharmil
Messages: 6
Registered: August 2010
Location: Mumbai, India
Junior Member
@halfer - Thank you so much for such a prompt reply.

Could you help me understand where I could place a global component. I have a global partial in my global layout that I need to feed logic. Is this possible?

----

Here are more details on what I am trying to achieve:
* I have a small feature in my global header that shows the visitor's city location based on IP address.
* I initially started developing the code to get the city location, in the "index" action of the "home" module. Here I would set the location variable to persist in the sfUser object.
* The view of this is in a partial called "_location.php" included in "layout.php" and is passed the location variable from the sfUser object.
* Unfortunately while testing other pages i realized that the variable will only be calculated when the "home" module is invoked.

I am looking for a place to call this code that would be invoked when my global layout.php is rendered regardless of what module is called upon. I was thinking of putting it in the front controller - index.php but I am not sure if that's is the right thing to do, and I am not sure getting the simplicity to call on objects available via "$this->" that I get in module actions.
Re: Actions Class Corresponding To Global Layout (layout.php) [message #103405 is a reply to message #103398 ] Mon, 02 August 2010 12:19 Go to previous messageGo to next message
halfer  is currently offline halfer
Messages: 9535
Registered: January 2006
Location: West Midlands, UK
Faithful Member
You're presently using a partial which needs to do the location lookup itself. Rather than putting that in the home page and then reading it from sfUser, put it in a component instead.

This means that, in your layout, you will use include_component instead of include_partial, and your component will be defined in a module somewhere in your application. You might to choose to put it in a module called "components", or "common" maybe.

The next thing you should do is go to the Symfony documentation, and read up on how to use components. They're very easy, and of course there's no point in me replicating the instructions here.


Remember Palestine
Re: Actions Class Corresponding To Global Layout (layout.php) [message #103406 is a reply to message #103398 ] Mon, 02 August 2010 12:22 Go to previous messageGo to next message
halfer  is currently offline halfer
Messages: 9535
Registered: January 2006
Location: West Midlands, UK
Faithful Member
I should add, by way of explanation, that "the place to call this code" is *inside* the component. That's the point of components: they're like a partial, but they can execute their own logic, like an action.


Remember Palestine
Re: Actions Class Corresponding To Global Layout (layout.php) [message #103407 is a reply to message #103405 ] Mon, 02 August 2010 12:32 Go to previous messageGo to next message
sharmil  is currently offline sharmil
Messages: 6
Registered: August 2010
Location: Mumbai, India
Junior Member
I was reading up on components while waiting on your response Smile I've done what you said and it works really well so I appreciate the guidance.

My confusion is that if symfony supports this inherent module called "global" where I can place partials, why is there no structure to place components there as well?

Nonetheless, for right now your suggestion works great so thanks again!
Re: Actions Class Corresponding To Global Layout (layout.php) [message #103408 is a reply to message #103398 ] Mon, 02 August 2010 12:48 Go to previous message
halfer  is currently offline halfer
Messages: 9535
Registered: January 2006
Location: West Midlands, UK
Faithful Member
There's no need for a "global" location for components because you can put them in wherever module you want. Incidentally you can do the same with partials: you can put them in your own location, and refer to them using myModule/partial, rather than global/partial.

Edit: btw, glad you've sorted it out Very Happy

[Updated on: Mon, 02 August 2010 12:49]


Remember Palestine
Previous Topic:How to pass session id in URL?
Next Topic:Adding an empty choice while passing a Doctrine object to sfWidgetFormChoice
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software