Difference between #2 and #3 of
History Autocomplete

Revision #3 has been created by Maurizio Domba Cerin on Mar 28, 2012, 7:52:51 AM with the memo:

fixed code tabs/spaces
« previous (#2)


Title unchanged

History Autocomplete

Category unchanged


Yii version unchanged

Tags unchanged


Content changed

public $model;
public $attribute;
public $criteria=array('limit'=>5);

public function run()
$criteria=new CDbCriteria($this->criteria);          $criteria->addCondition("{$this->attribute} IS NOT NULL AND {$this->attribute} LIKE :param");
$criteria->group=$this->attribute;          $criteria->order="COUNT({$this->attribute}) desc"; $criteria->params[':param']='%'.$_GET['term'].'%';          $results=array();          foreach (CActiveRecord::model($this->model)->findAll($criteria) as $record)              $results[]=$record->{$this->attribute};          echo CJSON::encode($results);
public function actions()
{ return array( 'searchCompany'=>array( 'class'=>'SearchAction', 'model'=>'Request', 'attribute'=>'company', ) ); }
<?php $this->widget('zii.widgets.jui.CJuiAutoComplete',
    array('model'=>$model,     'attribute'=>'company',      'htmlOptions'=> array('maxlength'=>300, 'class'=>'text'),     'sourceUrl'=>'searchCompany'));?> ``` This method is quite efficient and usually customer like it, because is based on the laziness of the users.
3 0
Viewed: 9 830 times
Version: 1.1
Category: How-tos
Written by: zaccaria
Last updated by: Maurizio Domba Cerin
Created on: Jan 23, 2012
Last updated: 6 years ago
Update Article


View all history