slt je cherche a faire un autocomplétion sur su champ 'code postal' dans mon formulaire 'devis'.
devisFrom:
1 2 3 4 5 6 7 8
| public function configure()
{
sfProjectConfiguration::getActive()->loadHelpers('Url');
$this->widgetSchema['code postal'] = new sfWidgetFormJQueryAutocompleter(array(
'url' => url_for('@autocomplete_test'),
'config' => '{scrollHeight: 200, minChars: 1, delay: 500}'
));
} |
dans la class CpTable.class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| public function retrieveForSelect($q, $limit)
{
$query = $this->createQuery('t')
->where('t.cp LIKE ?', '%'.$q.'%')
->orderBy('t.cp')
->limit($limit)
->execute();
$response = array();
foreach($query as $data)
{
$response[$data->getCp()] = $data->getCp();
}
return $response;
} |
Dans le ficher action de devis:
1 2 3 4 5 6 7 8
| public function executeAjax(sfWebRequest $request)
{
$this->getResponse()->setContentType('application/json');
$data = Doctrine_Core::getTable('Cp')->retrieveForSelect($request->getParameter('q'), $request->getParameter('limit'));
return $this->renderText(json_encode($data));
} |
la route:
1 2 3
| autocomplete_test:
url: /devis/autocomplete
param: { module: devis, action: ajax } |
le problème et qu'il ne propose rien
et avec firebug il y a :
GET http://test/autocomplete?q=nico&limit=10×tamp=1337454136740 404 Not Found 17ms
Partager