Putting (hardcoded) ids in routes |
In the tutorial, in the Routing section (https://codeigniter4.github.io/userguide...uting.html), the following code is used to map a route 'blog/joe' to a hardcoded id 34.
PHP Code: $routes->add('blog/joe', 'Blogs::users/34'); I want to do something similiar, mapping page slugs to my Page controller with a certain id. I am using the following code to do this, where $page is the page variable. PHP Code: $routes->get( $page->slug, 'Pages::id/' . $page->id ); I can't get this to work. When I visit localhost:8080/my-page-slug I get a 404-error, saying Controller method is not found: id\123. Am I doing something wrong with the mapping? Because if I visit localhost:8080/pages/id/123 it does work as expected. I was wondering if it would be a problem if I add multiple slashes to the slug, for example, "/parent/child". However, I don't think that that is the problem since the error message seems to indicate that the mapping at least partially succeeded. I hope someone can explain me what I am doing wrong or at least verify that I am not the only one that is having a problem with this. EDIT: OK, seems that I found the cause. In checkRoutes() in codeigniter4->framework->system->Router->Router.php the following code replaces all slashes with backslashes (lines 471 to 474). PHP Code: elseif (strpos($val, '/') !== false) It would be great if anybody could explain why this code is necessary and if I am doing something wrong with my routing that gives me these issues. |
Messages In This Thread |
Putting (hardcoded) ids in routes - by WhiteListed - 03-14-2019, 07:12 AM
RE: Putting (hardcoded) ids in routes - by WhiteListed - 03-14-2019, 12:38 PM
RE: Putting (hardcoded) ids in routes - by puschie - 03-15-2019, 04:54 AM
RE: Putting (hardcoded) ids in routes - by arunwalls - 04-06-2019, 03:44 AM
|