To add a tokenizer in yii framwork is very easy,i want to show it by an example,basically two files are used in my example
1.controllers/userController.php
2.views/user/index.php
First of all you have to download tokenizer from this link
http://www.yiiframework.com/extension/tokeninput/files/tokeninput-0.2.zip
unzip this file and put the tokeninput folder in the extension folder of the yii framework which is present inside protected folder
Code for the index.php file:
[color="#000080"]<?php
$this->breadcrumbs=array(
'User',
);?>
<?php $form=$this->beginWidget(‘CActiveForm’, array(
'id'=>'user-form',
'enableAjaxValidation'=>false,
)); ?>
<div class="row">
<?php echo $form->labelEx($model,'name'); ?>
<?php $this->widget(‘ext.tokeninput.TokenInput’, array(
'model' => $model,
'attribute' => 'name',
'url' => array('user/search'),
'options' => array(
'allowCreation' => true,
'preventDuplicates' => true,
'theme' => 'facebook',
)
)); ?>
<?php echo $form->error($model,'name'); ?>
<?php $this->endWidget(); ?>
</div>
</div>[/color]
code for the controllers file:
[color="#0000FF"]public function actionSearch($q)
{
$term = trim($q);
$result = array();
if (!empty($term))
{
$sql="SELECT name FROM tbl_user where name like '%$term%'";
$cursor =Yii::app()->db->createCommand($sql)->query();
if (!empty($cursor) && $cursor->count())
{
foreach ($cursor as $id => $value)
{
$result[] = array('id' => $value['name'], 'name' => $value['name']);
}
}
}
header('Content-type: application/json');
echo CJSON::encode($result);
Yii::app()->end();
}[/color]