当我从下拉列表中选择客户名称时,我想将客户ID从视图发送到控制器,它会将客户的ID发送给控制器。 这是我的视图文件'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>
这是我的控制器代码'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);
}
答案 0 :(得分:0)
尝试这样..它正在工作。希望这会有所帮助。
查看:强>
//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 file code. just add a variable parameter to hold the id in action method.
public function youaction($id){
echo "id : ".$id; // customer id
}