在 Codeigniter 中获取查询字符串值

Get Query String value in view in Codeigniter

我正在使用 Codeigniter,我想从查询字符串中获取值。 假设这是我的 url :http://localhost/Myapp/controller/method/6.

我想在不使用控制器的情况下在我的视图中获得这 6 个。我试过这段代码,但没有用。 使用下面的控制器,即 edit_started($c_id) 我到达了目标视图,但是在目标视图上有一个按钮,我在该按钮上调用了 refresh_div() 函数来加载 div 我得到 moveable_elements 进入主视图,即目标。我的主要 url 是 localhost/Myapplication/Controllername/edit_started(6) 但是在用 $this->uri->segment(n) 得到它时它给出 show_data 即 ajax 一个 url 而不是原来的 localhost/Myapplication/Controllername/edit_started(6).

Controller:

  public function edit_started($c_id)
    {   
    $data['result']=$c_id;
    $this->load->view('goal',$data);
    }

View:

$(document).ready(function(){

      function refresh_div()
      { 

        $.ajax({
        type: "POST",
        url: "<?php echo base_url(); ?>" + "dashboard/show_data",
        cache: false,
        dataType: "json", 
        success: function(data){

        $('#demo').html(data);

        } 
});

dashboard.php

public function show_data() {

$this->load->model('login_database');
$data['query']=$this->login_database->get_all_topics();
$this->load->helper('url');
$filter_view=$this->load->view('moveable_elements', $data,TRUE);
echo json_encode($filter_view);

}

现在 moveable_elements 是我想要获取查询字符串的视图。

尝试:

echo $this->uri->segment(4); 

echo $this->uri->segment(3); 

没有引号。

**Please use 4 instead of 3**
echo $this->uri->segment(4);
OR
Please don't use "method" in url. Use them in your controller method
http://localhost/Myapp/controller/6
For eg:
function function_name(){
$this->load->model('model_File_Name');
$Create an Array = $this->model_File_Name->function_name_created in model();
$this->load->view(view_file_name,$Array_Name);
}

我认为这就是您要查找的行

$query_string_value = $this->uri->segment($this->uri->total_segments());