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)

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 406 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