Route structure of Codeigniter

Asked

Viewed 316 times

0

I have the following route:

$route_pri = $this->uri->segment(1);
$route_sec = ($this->uri->segment(2)==true) ? $this->uri->segment(2) : '';
$route_three = ($this->uri->segment(3)==true) ? $this->uri->segment(3) : '';

$second = ($this->uri->segment(2)==true) ? $this->uri->segment(1).'/(:any)' : $this->uri->segment(1);
$second = ($this->uri->segment(3)==true) ? $second.'/(:any)' : $second;

$route[$second] = 'leftcontent/allowed/'.$route_pri.'/'.$route_sec.'/'.$route_three;

What would be the best way to organize it? I don’t want to have to type in all the routes I need to chart for each one, so this way I can recover, I just found disorganized.

  • Are you setting up the routes dynamically? because?

1 answer

2

Codeigniter provides a configuration file to handle only routes. This file is in the application/config/Routes.php. If you want to know all the possibilities available I advise you to read the documentation.

  • Yes, it is in it that I set up these routes, automatically, because if they were manual, I would have to assemble at least 10 different routes, and this way, it goes routing as I need, only I found disorganized this way, maybe the nomenclature is not adequate.

  • Is there any way you could better explain how this route of yours works? From what I understand you are sending to the leftcontent class and running the allowed method and as parameter you are passing 3 arguments that the user can type in the url. That’s it?

  • Yes, they are links. From each one... and if it does not exist, I take to the 404.

  • Perhaps the best alternative would be to make this treatment in your method. Since it’s all going to the same method of the same class, in this method you check the url and do what you have to do according to the data you get. A good way for you not to keep rewriting code and polluting your method is to use a function for it. The first thing your method does is to call this function that takes the values of the url and returns what you need.

  • I haven’t told you but you can build a helper file and upload it, and any function you set there will be available anywhere in your application

Browser other questions tagged

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