How to call private controller function from view with javascript |
[eluser]greatrat00[/eluser]
Hi, I'd like to call some controller functions in real time in order to get database data. However, I'd like these functions to be private in order to prevent users from calling them via URL. I believe this must be done in javascript (due to the real time aspect). I usually call public functions via ajax, but how do I call private functions? Thanks, Adam
[eluser]ivantcholakov[/eluser]
Test this within a controller: Code: protected _this_method_is_not_accessible_through_url() Edit: Of course, you may move the logic within a model, if you have to use it repeatedly in other controllers. Edit 2: Sorry, you are asking for something else.
[eluser]greatrat00[/eluser]
Hi, The question is how to call a private function in real-time or asynchronously from a view.
[eluser]ivantcholakov[/eluser]
The controllers's method should be accessible. You have to apply another kind of protection. As I can imagine, your AJAX call may be the POST type, then, you may pass CSRF or custon security token. The method should validate the request and to execute or reject it. I don't use such a protection yet, this is all I can say.
[eluser]jonez[/eluser]
[quote author="greatrat00" date="1394834429"]Hi, The question is how to call a private function in real-time or asynchronously from a view.[/quote] You can't, private methods aren't accessible from a web request. An AJAX call is the same as any other request, the route has to be public for you to make a request to it. Create a public wrapper that calls your private method and make your AJAX call use the URL to the wrapper. Code: private function _ajax_private( ) { http://www.w3schools.com/jsref/met_win_setinterval.asp Code: var timer = setInterval( function( ) { |
Welcome Guest, Not a member yet? Register Sign In |