Hola a todos !! les saludo desde Colombia. Soy nuevo en Yii y estoy desarrollando mi primer proyecto con este framework y necesito que alguno de ustedes me ayude con el siguiente problema:
Quiero usar CAutocomplete y luego de seguir las instrucciones dadas en la web de Yii, esta no me funciona y creo que es por que el action AutoCompleteLookup no se ejecuta en el controlador SitioController. El ejemplo lo tome de http://www.yiiframework.com/doc/cookbook/25/ y este es el código que tengo en el form:
<?php $this->widget(‘CAutoComplete’,
array(
//name of the html field that will be generated
‘name’=>‘Sitio_ID’,
//replace controller/action with real ids
‘url’=>array(‘SitioController/AutoCompleteLookup’),
‘max’=>10, //specifies the max number of items to display
//specifies the number of chars that must be entered
//before autocomplete initiates a lookup
‘minChars’=>3,
‘delay’=>500, //number of milliseconds before lookup occurs
‘matchCase’=>false, //match case when performing a lookup?
//any additional html attributes that go inside of
//the input field can be defined here
‘htmlOptions’=>array(‘size’=>‘60’),
‘methodChain’=>".result(function(event,item){\$(\"#Sitio_ID\").val(item[1]);})",
));
?>
<?php echo CHtml::hiddenField(‘Sitio_ID’); ?>
//*******************************************************************
Y en el controlador esto:
//Action
public function actionAutoCompleteLookup()
{
if(Yii::app()->request->isAjaxRequest && isset($_GET[‘q’]))
{
/* q is the default GET variable name that is used by
/ the autocomplete widget to pass in user input
*/
$name = $_GET[‘q’];
// this was set with the "max" attribute of the CAutoComplete widget
$limit = min($_GET[‘limit’], 50);
$criteria = new CDbCriteria;
$criteria->condition = “Tipo <> ‘Dirección’ AND NombreSitio_ID LIKE :keyword”;
$criteria->params = array(":keyword"=>"%$name%");
$criteria->limit = $limit;
$SiteArray = SitioTotal::model()->findAll($criteria);
$returnVal = ‘’;
foreach($SiteArray as $Site)
$returnVal .= $Site->getAttribute(‘NombreSitio_ID’).’|’.$Site->getAttribute(‘Sitio_ID’)."\n";
echo $returnVal;
}
//die();
}
Agradeceria enormemente a quien me resolviera este inconveniente ya que llevo varios dias en ello y he recurrido a $form->dropDownList como función alterna.
Gracias,
JJHA.