This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

Invalid argument in supplied for foreach().. : in sfWidgetFormJQueryAutocompleterMany.class

Forum to discuss ExtJS and other JS plugins

Invalid argument in supplied for foreach().. : in sfWidgetFormJQueryAutocompleterMany.class

by aszrool » Thu Apr 15, 2010 4:41 am

I had followed the guide in http://forum.symfony-project.org/index.php/m/78548/ and code snippet in http://snippets.symfony-project.org/snippet/336 for autocomplete in sfFormExtraPlugin. Everything run smoothly but only in my form, I got this error messages.
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?
aszrool
Junior Member
 
Posts: 8
Joined: Mon Mar 01, 2010 9:53 am