#1
I added this to custom_routing.php:


I tested with this url http://localhost/tr_custom_routing/e/info/1 for http://localhost/tr_custom_routing/events/show/1 and received the following message... ERROR: View file does not exist at: /tr_custom_routing/modules/e/views/show.php

It works fine if I use "events" instead of "e" for the first part of the custom route so not sure why it doesn't recognize it.


FYI... I'm using (:any) for the wildcard for now because I eventually want to fetch the record based on the url_string field, but that won't work until I change my show method.
#2
Hi mjim,

I'd start looking in the engine folder > 'get_segments.php' at method:

and engine > Pagination.php:


Where all the magic happens with CUSTOM_ROUTES
#3
Thanks DaFa

Based on this doc https://trongate.io/docs_m/information/advanced-custom-routing, I set up a similar custom route like this which should work on a new app:



When I var_dump $data in that file before Template::display($data) I see the following on this page: http://localhost/tr_custom_routing/e/info/1



Therefore on a custom route where the view segment is "info" it has ["view_file"]=> string(4) "show" which is correct.

However, the custom route first segment is "e" and I don't see ["view_module"]=> string(4) "events" in the var_dump.

This means the first segment of the custom route is not being passed along in the $data to Template::display($data), which is why I get this ERROR: View file does not exist at: /Applications/XAMPP/xamppfiles/htdocs/tr_custom_routing/modules/e/views/show.php

Where does the $data come from that is sent to this file -> /public/themes/default_admin/blue/admin.php?

If I can track that then I should be able to find the source of the error.
#4
the $data comes from the controller, in your case method 'info'

where you also need to add this to your info method:


And I think you have the key => value around the wrong way, where the custom route should be

for http://localhost/tr_custom_routing/evets/show/1 to work

Also, you should change the custom route to (:num) if you only want valid integer IDs to be passed through
#5
Thanks DaFa, the fix was in the controller file.

The $data in the show method in the Events controller already included the view_file:


So the custom route knows that we need that view file regardless of what I set as the second segment, in this case 'info'.

Similarly, I added the view_module so the custom route knows that we need that view module regardless of what I choose for the first segment, in this case 'e'.



Now this custom route works properly;


To complete this I'll change the show method to search for the url_string instead of the id in segment 3.
#6
Yep, we've learnt something with this post. The clear take away is when you want to add a custom route, you MUST help the framework with these two lines in your methed for it to work.