How to pass Parameters to Partials and Components? - symfony1

I'm pretty new to the Symfony Framework and currently searching for the Best-Practice way to pass Parameters from a search to the included partials.
Currently I'm checking for the Parameter in the executeSearch Method and then setting a variable that is available in the searchSuccess.php File.
In the searchSuccess.php File I'm simply passing the variable to the Partial in the include_partial Method in the array. I keep passing the variable around until I'm in the correct partial.
My Method seems to complicated and wrong, but it seems I can't access the sfRequest variables outside the executeSearch Method?

You can access the request object in any template by calling $sf_request.

Related

OGNL needs to call a method

I need to call a method from my action object inside the JSP, something like:
var currentStatus = ${getCurrentStatus()};
I cannot call an attribute, and I tried following this answer (How to call an action method using OGNL) and it didn't work.
There are a variety of ways to call methods (on actions, on other objects, or static methods from classes) from OGNL.
In this case, however, I don't see any issue with using a normal accessor. Note that the JavaBean convention is almost (completely?) about naming. A getter named getCurrentStatus(), accessed simply in OGNL via currentStatus, can contain whatever code you want.
This could include the DB access you mention in your question, etc.

How do I pass variables between pages - the OOP way in Rails?

I am trying to convert my website from Wordpress/php to Ruby on Rails and am having trouble grasping the conceptual side of OOP/MVC in Ruby/Rails as it relates to passing variables between views. I have found many answers to how to do it, but I am still unclear exactly what is going on and I think it is because I have not grasped the concept of classes and methods in this particular context.
In PHP I can simply pass a variable to another page like this:
http://myurl.com/scores/?myteam=team1
To do this in Rails - pass one variable (myteam in the example previous) between views using a link - then:
what methods, classes and objects are involved (and I need to set up) and
at what point are they initialized?
Read this Controller's Rails guide, especially parameters section: http://guides.rubyonrails.org/action_controller_overview.html#parameters
Basically you will get access to this variable in controller using params hash, for this example it will be params[:myteam].

Global variable that is accessible in models without passing any information from controller

I know how we can declare global variable in config file and then access through
Service Locator
Currently I am getting this Global variable in controller with the help of service locator and then pass it to models while creating object.
Question: Is it possible that I can get the Global variable in model directly rather than passing in all the models through controller?
Yes it is possible to get the variable declared in global file into model directly. Instead of declaring it as variable, just define it as constant in the global file so that you can access that variable easily in any models.
define('VAR_NAME',Value);
and access the variable using.
constant('VAR_NAME');
Hope it helps
Thanks

Grails Possible to use javascript with <g:if>?

Is it possible to use the state of a javascript global variable in the "test=" of a tag? If so how would I access that variable since ${} is usually to evaluate variable sent from the Controllers.
Try using a jQuery function in conjunction with JSON data returned from your controller. You may be able to accomplish what I think you need.

Accessing user session from a custom routing class

Is there some way to acces the user object from a custom routing class?
I'd like to add a parameter when generating a url, and that parameter is inside the user session, so I need to access it.
The only way I found to access is using the sfContext::getInstance()->getUser(), but it's known to be inefficient.
Thanks!
I'd write it the way you mention - I've used that method in similar situations and never had an issue performance wise, and suspect you will be the same.
Also, never heard this mentioned as inefficient, but it is a little bit frowned upon because it couples the route to the context. An alternative that would overcome this would be to pass the variable to the route as you would any other parameter (or the user object if you need the whole thing). If you need to do this a lot, you can always make a custom url helper that wraps the existing url_for method, adding this param to any other details passed.
A workaround I have implemented (for now), is getting some data from somewhere (not ideal, I'm willing to access the user session yet), and set a new parameter inside $params, in the generate method of the custom routing class.
Hope it helps...

Resources