How do I get the $ _GET value of a URL in CodeIgniter

4

I am sending a value get through a link for example:

<a href="/admin/editar_user/5">Editar</a>

And there in the method of my controller that calls the view I get:

public function editar_user(){
    $this->load->view('admin/editar_user');
}

So far he's calling the view the way I wanted it, but I want to know how I get that value sent via get which in this case would be 5

For example:

public function editar_user(){
        // comando pegar valor get  5
        $this->load->view('admin/editar_user');
    }

How do I get the value get ?

    
asked by anonymous 11.03.2014 / 16:04

3 answers

7

You can use the class:

URI Class

  

The URI Class provides functions that help you retrieve information   from your URI strings. If you use URI routing, you can also retrieve   information about the re-routed segments.

It basically helps you retrieve segments from a URL.

$this->uri->segment(n)

Where n is the segment number you want to return.

Passing Parameters on the Controller

URL Example:

site.com.br/index.php/produtos/sapatos/tipo/123

Controller

<?php
class Produtos extends CI_Controller {
    public function sapatos($tipo, $id)
    {
        echo $tipo;
        echo $id;
    }
}
?>
    
11.03.2014 / 16:11
7

If you are using
like this: site.com.br/index.php/produtos/sapatos/tipo/123
will be a parameter in the controller
creating the method like this:

public function sapatos($tipo, $id){
    echo $tipo;
    echo $id;
}

if you use url like this:
like this: site.com.br/index.php/products/shoes/?tipo=1&id=123
The method has to look like this:

public function sapatos(){
    echo $this->input->get('tipo'); // recupera a informação via get
    echo $this->input->get('id');
} 
    
12.03.2014 / 14:08
2

No editar_user() set an argument for example $id , when the user clicks the link the 5 value will be assigned to $id

public function editar_user($id){
        echo $id;
        $this->load->view('admin/editar_user')
}
    
11.03.2014 / 16:21