2015-11-02 77 views
1

當我從下拉列表中選擇客戶名稱時,我想將客戶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'].'&nbsp'. $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

否點擊客戶名稱 –

+0

後需要jquery。 –

回答

0

嘗試像工作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'].'&nbsp'. $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 
} 
相關問題