We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Forward to the same controller with the same action.

I'm now writing a members system. I have a controller named "Controlpanel" with an action "loginAction" inside. If a user request "controlpanel/login" with a "get" method, and he/she would see a login form. If a "post" request is sent, I would check the database with the user name and password. If correct forward( with dispatcher->forward() ) to "controlpanel/index", otherwise forward to "controlpanel/login" again.

My Question is that: If I forward to "controlpanel/login" again, I would get a unlimited loop...... I thought it's because the user's request is forwarded to "controlplanel/login" itself with "post" but not "get". Is there any method to forward to loginAction itself but change the method to "get" ?



7.5k
Accepted
answer

Maybe you should just use redirect instead of forward to controlpanel/login. This way you method will be GET



1.2k

Thanks! This works!! ^ ^