Difference between #2 and #3 of
History Autocomplete

Changes

Title unchanged

History Autocomplete

Category unchanged

How-tos

Yii version unchanged

Tags unchanged

autocomplete

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);
 
    }
 
}
}
[...]
```php
public function actions()
{ return array( 'searchCompany'=>array( 'class'=>'SearchAction', 'model'=>'Request', 'attribute'=>'company', ) ); }
```
[...]
```php
<?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
9 followers
Viewed: 20 419 times
Version: 1.1
Category: How-tos
Written by: zaccaria
Last updated by: Maurizio Domba Cerin
Created on: Jan 23, 2012
Last updated: 12 years ago
Update Article

Revisions

View all history