Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POST in PHP MVC Controller?

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_controller.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

like image 958
BeMeCollective Avatar asked Dec 28 '09 09:12

BeMeCollective


1 Answers

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 the POST request comes, it treats its URI in the same way. The later actions are in the hand of the 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 the wrong parts. MVC is not the 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 the name "MVC" became famous as 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. The implementation of the 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.

like image 81
stroncium Avatar answered Oct 26 '22 23:10

stroncium