Welcome Guest, Not a member yet? Register   Sign In
Customized routing
#1

(This post was last modified: 06-14-2022, 11:19 PM by groovebird.)

Hi,

in CI3 i used a MY_Router class and a customized _parse_routes function. If i find a product url in the products table i used my own (overwritten) _parse_routes and then i used _set_request to specify the controller i want to use. Otherwise i used the CI3 _parse_route function for all other routes. What is the way for doing that in CI4?

The resaon:
I have product pages, but my url has no specific word like "products" in order to write this route in the routes file. (:any) is not working, because all other routes will be affected.
Reply
#2

See https://forum.codeigniter.com/showthread...#pid396876
Reply
#3

(This post was last modified: 06-15-2022, 12:08 AM by groovebird.)

Hi,

i don't use locales or translations. My URL is something like domain.com/product-name-2 or domain.com/other-product

Do i missing anything?
Reply
#4

It is an example to use your own Router.
Reply
#5

I don't know if it is useful, but i found a solution.
I extended the RouterCollection class and within this class i created with the $this->get(), $this->post() method my custom routes from the database (url's are stored in a database table)

@kenjis what i don't know: Are this routes called first or at the end after my other routes in the Routes.php?
Reply
#6

I don't know your customization, but the current Routing behavior is:
https://codeigniter4.github.io/CodeIgnit...e-priority
Reply
#7

(08-19-2022, 04:14 PM)kenjis Wrote: I don't know your customization, but the current Routing behavior is:

I did this:

PHP Code:
class RouteCollection extends BaseRouteCollection
{
    public function 
__construct()
    {
        
parent::__construct();

        
$this->get('my-custom-route', [App\Controllers\MyController'index'])
    }


Will this route be called before the routes in Routes.php?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB