views:

169

answers:

2

Hello All,

I am learning the PHP MVC pattern for my backend implementation. Looking at this excellent example:

Implementing MVC in PHP: The Controller

http://onlamp.com/pub/a/php/2005/11/03/mvc%5Fcontroller.html

I feel comfortable with the execution flow in a GET. But there is no mentioning of what happens in a POST. What would the typical controller code for the POST do? I wonder if I am misunderstanding something obvious here, since I can't find similar situations in previous SO posts or Google.

For example: An app to manage persons,(name, last, age) wants to add a record to db when a POST hits the controller. What happens next? My guess is that the 'View' is not used at all, or maybe for confirmation? Is there just a call from the controller to a model class that adds a record to db? Or do I skip the controller altogether for a POST and go directly to an "add record" script?

Is there any available example?

Thanks in advance, Ari

+1  A: 

Typically, the controller would process the request (the controller processes ALL requests), then call into the model to actually manipulate data based on the request, and then either redirect to somewhere else (triggering a new GET request), or invoke a view to output a resulting page.

Amber
+1  A: 

Well, POST is basically the same as GET, just some random chunks of info client sended to server. So you can treat it the same way.

I worked with CodeIgniter MVC framework in php. It uses GET URI to route to controller and it's methods. When it happens the POST request comes, it treats it's URI in the same way. The later actions are in the hand of programmer, who accesses POST request data directly or through some wrapper, and he can also don't use it at all.

I need to say, that you focus on wrong parts. MVC is not model of everything, and it doesn't say how to treat POST or GET requests. It's just a simple principle known many years before MVC name became famous. The principle about splitting of logic, data and representation. And most of software(from old to new) actually do this splitting, because it is very hard not to do this in most cases. In some apps the borders are not so evident, some of them even haven't object model. Implementing of app is always up to you, because MVC doesn't say you what to write, but just gives some clues about highest level organization of you code.

P.S. Sorry for my bad English.

stroncium
Thanks guys. Ill mark this one as the correct answer since it answers my question. Just wish to mention that I have worked with MVC in a desktop environment before, but the POST part got me confused. I'll try to treat it similar to a GET.RegardsAri
BeMeCollective