如何获取当前窗口URI的最后一段

时间:2015-12-30 07:54:08

标签: codeigniter

我当前的窗口网址http://192.168.20.2/vtp/attendance/rawAttendance和参数表单由ajax中的此网址"<?php echo base_url(); ?>index.php/attendance/submitParam"提交。使用以下代码

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

我得到了最后一个网址,但这不是当前窗口网址细分,这是参数形式的网址细分。当我提交参数表单时,如何在submitParam controller中获取当前窗口URL最后一段。

提交参数;

$("#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 );
        } 
    }

2 个答案:

答案 0 :(得分:1)

试试这个:

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

答案 1 :(得分:1)

在表单中添加名为url_parameter的隐藏字段。设置控制器中所需的最后一个参数的值,并通过post / get方法获取该字段的值。