Welcome Guest, Not a member yet? Register   Sign In
Routing by POST values

thanks xwero...

I don't think this is a problem (sending back data message) just becouse, as I wrote, I use this capabilities to load data via "ajax" call...

And.. I like the solution you posted...

However, I will love to hear some other considerations about this....

thanks all


[quote author="dop3" date="1222091611"]And, in fact, what's a "click on a link"?
No way, it's a user input!!! Wink[/quote]

No it's not. A link is a URI request. It may contain some query (GET) parameters which are user input. Same with a form. The action is the request, the POST data user input.

Quote:I know... it's so philosophical and abstruse! But think that I come not from web development... so maybe there are some "best practices" that i simply don't know! So, In Mirage I trust!!!

An to make it all a bit more complicated - in CI (and general 'modern day' practices) we snub query parameters in favor of nice, seo friendly URI's. :-)

Quote:I have a little javascript framework that handles just "ajax" calls and, even known that I could do this task using URI, I would to pass the params that specify the controller by POST... just becouse I think (I repeat, I think) it's more clear like this...

And there's nothing wrong with that. I've done my fair share of Desktop development and had similar considerations when I began with XHR, etc.

The thing you need to work out is how to make your frontend (client / javascript) work properly with your backend (server / CI ). While not enforcing it strictly CI out of the box is set to work with and encourage use of 'nice' URIs, establishing a MVC pattern that matches URI requests to controllers and their methods.

CI's router is built to remap URI requests to controllers/methods that have different names than provided in the URI. The controller itself evaluates POST data and then dispatches work to Models, Librariers, Helpers, etc. By thinking of using the Router to examine POST content your are attempting to significantly 'bend' CI to match your philosophy with minimal gain. A few adjustments on the frontend to work with the backend as designed would seem instantly more productive to me.

So along the lines of what xwero suggested... your frontend MUST request a URI anyway. Can't just send post parameters into the ether. :-) If you want to us a single controller to dispatch your requests the suggested approach will work. I'd use the special _remap() controller function to evaluate your POST data (probably in a giant switch) and then dispatch from there.

Again, you'll soon realize that you are going through too much work. Your controller will grow and you'll begin to wonder why you picked CI in the first place. If you use distinct URI's CI handles the dispatch for you, down to the action. The action knows what input to expect and you only need handle that portion of it. Probably handing it of to the model and generating a response.


Thanks Mirage...

I understand and (sadly Wink I agree!!!



Mirage the advantage of using a controller over the _remap function is that you are able to split the requests using methods. site.com/dispatcher/frontend, site.com/dispatcher/backend and you can split it up futher if you want.

dop3 wants to, as i understand it, create security to obscurity which is a good idea because javascript code is public. It's not a full proof method but it's an extra hurdle hackers have to take to misuse your server code.

@xwero -

I don't disagree with what you're saying as I think we're talking about the same thing. The remap() method doesn't doesn't prevent you from splitting the requests. It just make your url shorter.

Edit: And as the name (remap) suggests, it's kinda designed to do some late stage routing/dispatching. Since that's what the OP wanted to do, I felt it was the most natural approach.


Theme © iAndrew 2016 - Forum software by © MyBB