views:

159

answers:

2

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?

A: 

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.

benlumley
+1  A: 

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');
Geoffrey Bachelet