Just a quicky, as I had to spend 10 mins looking this up hopefully it’ll save someone else time later.
I need to retrieve a random user from the users table, but didn’t know how to express a random record… this method will return a single random user, or can take an argument to return more than 1 UserPeer
So it should take the value of the hints input element, go off to the 3rd party api, grab the info I need then pop it into the input that has an id of tags … only that doesn’t work, of course.
So what’s the solution?
Ok, a 3 step process, firstly we need to add script = true in our observe_field parameters, letting the observe_field know that it’s going to have script returned that it will need to execute
…now, I’m not entirely happy with this for 2 reasons. Firstly, the update parameter of the observe_field call is now redundant, and secondly, the id of the input we want to update is now harded in the view, so to at least get around that, we can add an extra parameter in the with part of observe_field like this:
Ever wanted to run some functions or create some variables before every action in a module? Or ever wanted to do something crafty after every action and before the template gets displayed?
Even if your answer is no, its good to be aware for future projects, that Symfony is hiding some very valuable methods of doing such things. Read on…
For doing stuff before every action in your module, just create a new function called preExecute() like so:
class demomoduleActions extends sfActions
{publicfunction preExecute(){// ... put your stuff here that you want to run before every Action ...}}
Equally for doing anything you like after every action in your module just create a new function called postExecute() like so:
class demomoduleActions extends sfActions
{publicfunction postExecute(){// ... put your stuff here that you want to run after every Action ...}}
It really is as simple as that. I stumbled across a little while ago whilst working on a project for a client of mine. So I thought I’d share this with you all.