如何将客户ID从视图发送到控制器
问题描述:
当我从下拉列表中选择客户名称时,我想将客户ID从视图发送到控制器,它会将客户ID发送到控制器。 这里是我的看法文件 'customerlifecycleanalytic.php'如何将客户ID从视图发送到控制器
<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);
}
答
尝试像工作this..Its。希望这会有所帮助。
查看:
//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
}
您在提交后的意思? –
否点击客户名称 –
后需要jquery。 –