Member Login | Not a member?

Problem with custom routing

Help Bar HomePost Reply

Comments for “Problem with custom routing”

Posted by mike on Apr 26th 2022 at 21:34 GMT

Hello everybody,
I am developing on a mac in localhost.
I have made a module from scratch and, after reading the documentation (chapter: Advanced Custom Routing), I decided to have a custom route for its index method: 'my-cal' => 'calendar'.
If I call the custom route without having logged in as admin, I get a 404 page.
If I log in as admin, I get the public template displayed with the following message:
"ERROR: View file does not exist at: /Users/this_user/Sites/my_app/modules/my-cal/views/calendar.php"
Notice the 'modules/my-cal/views/' part which causes the problem. Why is the custom route written before the 'view' part?

If I use the normal url 'localhost/my_app/calendar' everything works fine, (also without logging in because I don't check for anything)

I checked things with the members module.
I made a custom route 'my-members'=> members/manage'.
If I am not logged in, it correctly shows the admin login page as per its code.
After logging in, the 'my-members' route works perfectly.

Any thoughts?
Thank you for any help available.

Level One Member

mike
User Level: Level One Member
Date Joined: January 6th 2022

Posted by djnordeen on Apr 26th 2022 at 22:57 GMT

This comment was updated by djnordeen on Apr 26th 2022 at 22:58 GMT

Hello Mike,

'my-cal' => 'calendar'.

What is the name of the module you created and the name of the view file?

I suspect you need to say
'my-cal' => 'name_of_module_you_created/calendar'

Post your code inside tags Square Brackets with opening code and closing /code

Put your code here


Let me know if this works,
Dan

Early Adopter

djnordeen
User Level: Early Adopter
Date Joined: August 20th 2021

Posted by DaFa on Apr 26th 2022 at 23:38 GMT

This comment was updated by DaFa on May 10th 2022 at 22:26 GMT

Hi Mike,

Dan is right about sharing some code so we can see exactly what you are doing.

I just created a module called 'calendar' with the VS Code extension

class Calendar extends Trongate { function index() { $data['view_module'] = 'calendar'; $this->view('display', $data); } }

and added a custom route to 'custom_routing.php'
$routes = [ 'tg-admin' => 'trongate_administrators/login', 'tg-admin/submit_login' => 'trongate_administrators/submit_login', 'my-cal' => 'calendar' ]; define('CUSTOM_ROUTES', $routes);

Which works fine for me

Founding Member

DaFa
User Level: Founding Member
Date Joined: November 30th 2018

Posted by mike on Apr 27th 2022 at 07:53 GMT

This comment was updated by mike on Apr 27th 2022 at 15:08 GMT

Hi all,
thanks for the fast help.

Well.. as DaFa highlighted for me, I had forgotten to declare the view_module:

$data['view_module'] = 'calendar’;


I had also tried putting var_dumps in the get_segments function inside the engine to see what was happening...

Just couldn't see my mistake...

Dan, where can I find the text formatting guide for this forum? I just can't get my code properly formatted and I don't understand what you mean by: “Post your code inside tags Square Brackets with opening code and closing /code”

Thank you both again!

Level One Member

mike
User Level: Level One Member
Date Joined: January 6th 2022

Posted by djnordeen on Apr 27th 2022 at 10:13 GMT

This comment was updated by djnordeen on Apr 27th 2022 at 10:16 GMT

Not sure if there is a list.

To post code you use code tags.
You have a beginning code tag and then put your code, and end with a code tag.
Put the code tags below with square brackets around the [ ]. The. square brackets hide the word code.

code
"put your code here"
/code

Early Adopter

djnordeen
User Level: Early Adopter
Date Joined: August 20th 2021

Help Bar HomePost Reply

×