Selected id in a dropDownList

Hi!

I have a dropDownList who recibes data from de database. When I select one of the items, it calls the controller "admin/ajax/id/" to show a list of users in #list.

The problem is in the url, I need to put the id of selected user in the url, like this "admin/ajax/id/13". How can I do this?


echo CHtml::dropDownList('clientes','',CHtml::listData(Users::model()->findAll(),'id','name'),

                            array(

                                'ajax' => array(

	                                'type' => 'POST',

	                                'url' => Yii::app()->createUrl('admin/ajax/id/'),

	                                'update' => '#list'

                            ))); ?>   

                     

<div id="list"></div>

thanks!

I found how select the value of the selected id in jquery:


 'url' => 'js:alert($(this).val())',

This alerts the correct id.

But I dont know how join it with the php function to do the complete url:


'url' => Yii::app()->createUrl('admin/ajax/id/.js:$(this).val()'),

try like this:


echo CHtml::dropDownList('clientes','',CHtml::listData(Users::model()->findAll(),'id','name'),

					array(

						'ajax' => array(

							'type' => 'POST',

							'url' => Yii::app()->createUrl('admin/ajax/'),

							'data'=>"js:{clientId: $(this).val()}",

							'update' => '#list'

					))); ?>   



Thanks! it works great.

Is there another way to recibe data in the controller than this?


$id_client=$_POST['clientId'];

A Yii way, I tried


$id_cliente=$this->clientId;

but seems not work.

I found:

$id_clien=Yii::app()->request->getParam(‘clientId’);

Any better way?

whatever u do, ultimately u have to retrieve the data from where it is stored.

for POST nothing can be smaller than


$id = $_POST['id'];

either, u can create ur own function


public function p($param){

    Yii::app()->request->getParam($param);

}

by using getParam() u may not specifically check whether its coming from POST or GET, if u need so u can write separate function for both.