Generating URL Symfony sfFormExtraPlugin autocompleter
-
22-09-2019 - |
Question
Autocompleter has a required option - url. Problem is, it is used in Form.class where neither url_for() nor $this->getController()->genUrl() works. All the examples I saw use url as literal string, i.e.
$options = array('Model' => 'Model', 'url' => '/path');
Maybe I'm getting something wrong, but I believe writing URLs as string is not a good practice. Anyway practices aside, I can't get it working either due to using frontend_dev.php, I mean, what, am I supposed to manually change every Ajax URL after development is finished? It can't be like that.
What am I missing?
Solution
You have to generate the url from outside the form (most of the time, your action) and pass it as an option to your form:
$url = $this->generateUrl('my_route');
$this->form = new MyForm($object, array('url' => $url));
Then you access it within your form using the getOption
method:
$this->getOption('url');
OTHER TIPS
I have this issue with ajax too.
My current method is to ensure index.php works in the dev environment - I alter the front controllers to detect environment based on url, rather than to pass it as a string.