Hi,
I want to use dependent dropdowns in my jappendo. I have written the following code so far which is static and works. I want to make it dynamic.
$product = CHtml::listData(Products::model()->findAll(),'product_id','product_name');
echo CHtml::DropDownList('product_id[]','',$product, array(
'prompt'=>'Select Location...',
'ajax' => array('type'=>'POST',
'url'=> Yii::app()->createUrl( "PurchaseOrder/units"),
'update'=>'#param_id'
)));?>
<div id="param_id" class="row">
<?php echo CHtml::DropDownList('unit[]','',array(prompt=>'select')); ?>
</div>
And in my controller:
public function actionUnits()
{
$product_id = $_POST['product_id'][0];// this makes it static. i want to fetch product_id dynamically
$data=Products::model()->findAll('product_id=:product_id',
array(':product_id'=> $product_id));
$data=CHtml::listData($data,'unit','unit');
foreach($data as $value=>$name)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}
}
Please help.
Thanks