How to get an infinite route in Codeigniter?

Asked

Viewed 92 times

1

I have two urls:

And I’m having these Routes:

  • $route['search/(:any)'] = "Search/index/$1";
  • $route['search/(:any)/(:num)'] = "Search/index/$2/$";

I would like to use an infinite url but can’t get the desired result. Can someone give me a help? When I access the first url, it works correctly but the second url does not work. What I need is represented in the image below:

inserir a descrição da imagem aqui So I was watching here and the $_POST is going correctly but is not entering the index, IE, if I try to overwrite and eliminate the /index gives error. Summarizing, I think the error is in the same routing.

inserir a descrição da imagem aqui

  • Search/index/$2/$ seems to me a mere typo. wouldn’t it be just for the $(numerodoparametro) correctly in all cases? $1/$2/$3 etc?

1 answer

0

Try to use:

$route['busca/(:any)'] = "Busca/index/$1";
$route['busca/(:any)/(:num)'] = "Busca/index/$1/$2";

So you will access:

http://www.seusite.com.br/busca/qualquercoisa/umnumero

And he can be sued like that:

public function index($palavra, $numero = false){

}

For you to do endless routes like you said, you will end up generating errors, because as you do not know what is being passed in the URL and when, then it would be difficult.

You will have to create the routes according to the parameters that will be received.

  • 3

    Yeah, pretty much what I mentioned in the question. not posted as answer pq is not solution pro "infinity" that was requested (although I agree that it does not make sense to be infinite if of qq way will have to know how to deal with the parameters).

Browser other questions tagged

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