How to modify a url sent via get [Codeigniter] form?

Asked

Viewed 158 times

0

Guys I need to modify a url but don’t know how to do it. I have the following url:

http://wedding.axitech.com.br/?procuraonde=Palhoça&procuraoque=bolos

and need to turn to the url below:

http://wedding.axitech.com.br/palhoca/bolos

Can someone help me get this result on Codeigniter?

inserir a descrição da imagem aqui

1 answer

2

You can create a route where the segments will become the get parameters for a controller’s method or enter in the url the controller’s name and the desired method in the first and second segment respectively of the url. Segment is each value passed between the URL bars counting from the site’s base URL. The sequence is: url_base/controlador_ci/metodo_do_controlador/parametro1/paramentro2/... Where controlador_ci is the first segment, metodo_do_controlador the second segment, and so on. Here is an example of what the url you want with route would look like.

url: http://wedding.axitech.com.br/buscar/palhoca/bolos

access the file application/config/routes.php and create the route $route['buscar'] = 'Busca/efetua_busca';;

create the following controller:

Controller

public class Busca extends CI_Controller {

    public function __construct() {
        parent::__construct();
    }

    public function efetua_busca($onde, $oque) {
        /* $onde receberá palhoca e $oque receberá bolos. 
           A sequência é a mesma que passada na url */

        echo $onde; // imprime palhoca
        echo $oque; // imprime bolos
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.