I want to send customer id from view to controller when I select customer name from dropdown list it will send customer's id to controller. here is my code of view file 'customerlifecycleanalytic.php'
<select class="form-control selectpicker customerfilter">
<option value=''>Select Customer</option>
<?php
if (isset($customername)) {
foreach ($customername as $customernames) {
echo '<option value="' . $customernames['id'] . '" >' . $customernames['firstname'].' '. $customernames['lastname']. '</option>';
}
}
?>
</select>
here is my controller code 'Customerlifecyclecontroller'
public function actionCustomerlifecycleanalytic() {
$customername = Customer::model()->findAll("store_id='" . Yii::app()->session['store_id'] . "'");
$customerlifecycle = CustomerLifecycle::model()->findAll();
$this->renderPartial('customerlifecycleanalytic', array( 'customername' => $customername, 'customerlifecycle' => $customerlifecycle), false, true);
}
Try like this..Its working. Hope this will help.
View:
//view file code. Just add Onchange select attribute like below:
<select onchange="if(this.value) window.location.href='http://yourdomain.com/yourcontroller/youraction/'+this.value" class="form-control selectpicker customerfilter">
<option value=''>Select Customer</option>
<?php
if (isset($customername)) {
foreach ($customername as $customernames) {
echo '<option value="' . $customernames['id'] . '" >' . $customernames['firstname'].' '. $customernames['lastname']. '</option>';
}
}
?>
</select>
Controller:
// controller file code. just add a variable parameter to hold the id in action method.
public function youaction($id){
echo "id : ".$id; // customer id
}