- Code: Select all
Warning: Invalid argument supplied for foreach() in C:\www\sfprojects\invy\plugins\sfFormExtraPlugin\lib\widget\sfWidgetFormJQueryAutocompleterMany.class.php on line 106
This is my code..
form code
- Code: Select all
$autocompleteWidget = new sfWidgetFormChoice(array(
'multiple' => true,
'choices' => $this->getObject()->getItemId(),
'renderer_class' => 'sfWidgetFormJQueryAutocompleterMany',
'renderer_options' => array(
'config' => '{
json_url: " '.sfContext::getInstance()->getController()->genUrl('item/autocomplete').'",
json_cache: true,
filter_hide: true,
filter_selected: true,
maxshownitems: 8
}')
));
$this->widgetSchema['item_id'] = $autocompleteWidget;
class code
- Code: Select all
static public function retrieveSuggestions($q, $l, $c)
{
$itemid = Doctrine_Query::create()
->select('t.*, LOCATE(:token_raw, t.name) AS index')
->from('InvyItemRegistry t')
->where('t.name LIKE :token')
->orderBy('index')
->limit($l)
->execute(array('token_raw' => $q, 'token' => '%'.$q.'%'));
$jsonItems = array();
foreach ($itemid as $item)
{
$jsonItems[] = array('caption' => (string)$item->getName(), 'value' => $item->getPrimaryKey());
}
return $jsonItems;
}
action code
- Code: Select all
public function executeAutocomplete(sfWebRequest $request)
{
$this->getResponse()->setHttpHeader('Content-Type', 'application/json; charset=utf-8');
$items = InvyItemRegistry::retrieveSuggestions($request->getParameter('q'), $request->getParameter('l'), $request->getParameter('c'));
return $this->renderText(json_encode($items));
}
What am I suppose to do?
