I used CJuiAutoComplete and got the data from the db but I want to search the data details by clicking from the autocomplete list and go to the related view.
view.php
<?php
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name'=>'Book',
'source'=>$this->createUrl('/site/autocompletetest'),
'options'=>array(
'minLength'=>'2',
),
'htmlOptions'=>array(
'placeholder' => 'Search',
),
));
?>
controller.php
[font="Courier New"]public function actionAutocompleteTest() {
$res =array();
$result = array();
if (isset($_GET['term'])) {
$connection=Yii::app()->db;
$sql="Select name,id from book where name like :name or id like :name union select name,id from member where name like :name or id like :name";
$command =Yii::app()->db->createCommand($sql);
$command->bindValue(":name", '%'.$_GET['term'].'%', PDO::PARAM_STR);
$res =$command->queryAll();
if(!empty($res))
foreach($res as $mres)
{
$result[] = $mres['name'];
$result[] = $mres['id'];
}
echo CJSON::encode($result);
Yii::app()->end();
}
}[/font]
And I’m implementing this search on the menu bar for searching the books and memebers.
Please help me.Thankx.