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

Controllers with private parameters

Hey guys!

Maybe I'm wrong from the beginning but I have such an idea: I want to organize private parameters from controller. For example let say we have controller ErrorController with action errorAction. And when any error is occured we forwarding user to "error" controller and "error" action with some arguments that will say user what's wrong.

If I define action as: public function errorAction($code, $text) then any user who nows this route (supposing it should be /error/error/code/text) can do any ugly things.

How to act is this case? Rewrite router rule or something else? Hope you caught my idea. Thanks!

Are the codes standardized? Perhaps check against what your code list is and if not in that then just display. 'Ooops' or something?

edited May '15

you can use like this:

$this->view->forward(array('controller'=>'error', 'action'=>'error', 'params'=>'code='.$code.'&text='.$text));

in router set individually router for error controller

hey Evgeny,

Showing error to users is generally a bad idea, unless you throw very specific errors which you want to show to your users. Any other exceptions should be logged as they could contain data that can be used against you.

I would suggest setting up an event listener that handles the exceptions for you, see this thread for a demo:

https://stackoverflow.com/questions/14071261/how-to-setup-a-404-page-in-phalcon

Good luck!

Thank you guys for support!

I'm agree that showing errors is a bad idea. But it's important to know what kind of error we are talking about. I mean the only thing that I want to use the universal error controller that will not show any generated exceptions but only the handled ones. Idea is simple: error page with text content. And this text can vary but no one will have a permission to pass "text" var to controller.

I.e. if controller has $text in arguments list, router will assing a route such as /controller/action?text=foobar to handle the user input in future. Maybe I haven't got the routers and controllers idea properly but still keeping in mind that I want some of private arguments...

Hope I've explained my idea fully.

Btw sorry for my english.

The response object will, in the end do nothing more than generating the route and setting the propEr headera. What you want can be done Using cookies.

Thank you guys for support!

I'm agree that showing errors is a bad idea. But it's important to know what kind of error we are talking about. I mean the only thing that I want to use the universal error controller that will not show any generated exceptions but only the handled ones. Idea is simple: error page with text content. And this text can vary but no one will have a permission to pass "text" var to controller.

I.e. if controller has $text in arguments list, router will assing a route such as /controller/action?text=foobar to handle the user input in future. Maybe I haven't got the routers and controllers idea properly but still keeping in mind that I want some of private arguments...

Hope I've explained my idea fully.

Btw sorry for my english.