Autocomplete Yii from another model

Hi, everyone… I got some stuck when I used AutoComplete widget…

Let’s say I have 2 model,

A : id_a, column1, column2

B : id_b, id_a, column3, column4

I want to fill the form from model B, which whenever I start to type in id_a, the Autocomplete widget will show the value in Model A…

Here’s my code on views:




<div class="row">

        <?php echo $form->labelEx($modelB,'id_b'); ?>

        <?php echo $form->hiddenField($modelB, 'id_b');


				$this->widget('zii.widgets.jui.CJuiAutoComplete', array(

				'name' => 'FillField[B]',

				'sourceUrl' => array('B/suggestitem'),

				'value' => ($modelB->id_<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='B)' /> ? $model->id_a : $model->id_a,

				'options' => array(

					'showAnim' => 'fold',

					'select' => 'js:function(event, ui){ jQuery("#FillField_B_id_b").val(ui.item["id_b"]); }'

				),

				'htmlOptions' => array(

				),

			));

		?>

        <?php echo $form->error($modelB,'id_b'); ?>

    </div-->

and on my Controller :


public function actionSuggestItem() 

	{

        $criteria = new CDbCriteria;

        $criteria->select = array('id_b', 'id_a', 'id_a');

        $criteria->addSearchCondition('id_a', $_GET['term']);

        $criteria->limit = 15;

        $data = B::model()->findAll($criteria);


        $arr = array();

        foreach ($data as $item) {

            $arr[] = array(

                'id' => $item->id_b,

                'value' => $item->id_a,

                'label' => $item->id_a . ' (' . $item->id_a . ')',

            );

        }


        echo CJSON::encode($arr);

    }

that code was run so well, but it’s pulled the value from modelB (has been entered before)… my question is, can I get the value from modelA, especially whe i type in id_a field?

Thanks for any reply… :D

I am also facing the same problem…Can someone suggest me any good idea?