2015-12-30 72 views
1

我當前的窗口URL http://192.168.20.2/vtp/attendance/rawAttendance和參數表單通過這個URL "<?php echo base_url(); ?>index.php/attendance/submitParam"在ajax中提交。有了這個代碼下面如何獲取當前窗口的URI最後一段

$last = $this->uri->total_segments(); 
$data['lastSegment'] = $this->uri->segment($last); 

我拿到了最後的URL部分,但這不是當前窗口的URL段,這是參數形式的URL段。當我提交參數表單時,如何獲取我當前的窗口URL最後一段在我的submitParam controller中。

提交參數;

$("#submitparam").click(function (e) { // passing down the event 
        $.ajax({ 
         url: "<?php echo base_url(); ?>index.php/attendance/submitParam", 
         type: "POST", 
         data: $("#param").serialize() + '&fromAjax=' + true, 
         success: function (data) { 
          $("#result").html(data); 
         }, 
         error: function() { 
          alert("Fail") 
         } 
        }); 
        e.preventDefault(); // could also use: return false; 
       }); 

控制器:

public function submitParam() { 
     //post from view param 
     $round = $this->input->post('round', TRUE); 
     $batch = $this->input->post('batchid', TRUE); 
     $fromdate = $this->input->post('FromDate', TRUE); 
     $todate = $this->input->post('ToDate', TRUE); 

     //raw Attendance 
     $data['IDS'] = $this->AttendanceModel->raw_attendance_TID($batch); 
     $data['Dates'] = $this->AttendanceModel->raw_attendance_Data($batch,$fromdate,$todate); 

     //get Batch Attendance 
     $data['attendance'] = $this->AttendanceModel->get_attendance($batch,$fromdate,$todate); 

     //pass param to preview as attendance title 
     $data['batch']=$batch; 
     $data['fromDate']=$fromdate; 
     $data['toDate']=$todate; 

     //get url last segment 
     $last = $this->uri->total_segments(); 
     $lastSegment = $this->uri->segment($last); 

     //load view by url last segment 
     if ($this->input->post("fromAjax")) { 
      $this->load->view('attendance/'.$lastSegment, $data); 
     } 
    } 

回答

1

在表單中添加一個隱藏字段名爲url_parameter。在你的控制器中設置最後一個參數的值,並通過post/get方法獲取該字段的值。

+0

好主意先生。 –

1

試試這個:

$record_num = end($this->uri->segment_array()); 
+0

它也返回相同的,我的意思是參數url最後一段,而不是瀏覽器url最後一段。 –

相關問題