Working with tokenizer in yii

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'=&gt;'user-form',


'enableAjaxValidation'=&gt;false,

)); ?>

<div class="row">

&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'name'); ?&gt;

<?php $this->widget(‘ext.tokeninput.TokenInput’, array(

    'model' =&gt; &#036;model,


    'attribute' =&gt; 'name',


    'url' =&gt; array('user/search'),


    'options' =&gt; array(


        'allowCreation' =&gt; true,


        'preventDuplicates' =&gt; true,


        'theme' =&gt; 'facebook',


    )


)); ?&gt;


&lt;?php echo &#036;form-&gt;error(&#036;model,'name'); ?&gt;


&lt;?php &#036;this-&gt;endWidget(); ?&gt;

</div>

</div>[/color]

code for the controllers file:

[color="#0000FF"]public function actionSearch($q)

{


	&#036;term = trim(&#036;q);


	&#036;result = array();


	if (&#33;empty(&#036;term))


	{


		&#036;sql=&quot;SELECT name  FROM tbl_user where name like '%&#036;term%'&quot;;


		&#036;cursor =Yii::app()-&gt;db-&gt;createCommand(&#036;sql)-&gt;query();


	if (&#33;empty(&#036;cursor) &amp;&amp; &#036;cursor-&gt;count())


		{


			foreach (&#036;cursor as &#036;id =&gt; &#036;value)


			{


				&#036;result[] = array('id' =&gt; &#036;value['name'], 'name' =&gt; &#036;value['name']);


			}


		}


	}


 


	header('Content-type: application/json');


	echo CJSON::encode(&#036;result);


	Yii::app()-&gt;end();


}[/color]

NOTE: moved to proper section (Tips, Snippets and Tutorials instead of General Discussion for Yii 1.1.x)

When I follow instructions I get error:

"Fatal error: Call to a member function getValidators() on a non-object in /Yii/framework/web/helpers/CHtml.php on line 1758"

What should I do ?

i think your directory structure is not correct

i made a database with the name of dbusers having 3 fields id, name, address, i m only getting the name field from the database to show in the tokenizer.So first create the database

then create a a new yii application on this database, create curd with the tbl_user(inside dbusers database), you will got a controller with the name of "UserController" as well as in the view area a folder with the name of "user".The code i have pasted above is in the index.php file which is present in the user folder and the code i for controller is present in the UserController which is located inside the controllers folder.

Now I get this error:

Fatal error: Call to a member function isAttributeRequired() on a non-object in /Yii/framework/web/helpers/CHtml.php on line 1185

can you attach zip of project?

please send me your email address because the zip file i want to send u is about 5.73MB and i cannot send u through this forum because it supports only 2MB size, my email address is amjadiqbalkhanniazi@gmail.com