kitune
(Shinkitune)
March 11, 2011, 11:42am
1
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!
kitune
(Shinkitune)
March 11, 2011, 12:04pm
2
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'
))); ?>
kitune
(Shinkitune)
March 11, 2011, 2:04pm
4
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.
kitune
(Shinkitune)
March 11, 2011, 2:08pm
5
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.