PHP form post, automatically mapping to an object (model binding)
Posted
by Pete Nelson
on Stack Overflow
See other posts from Stack Overflow
or by Pete Nelson
Published on 2010-06-02T14:10:57Z
Indexed on
2010/06/02
14:23 UTC
Read the original article
Hit count: 263
I do a lot of ASP.NET MVC 2 development, but I'm tackling a small project at work and it needs to be done in PHP.
Is there anything built-in to PHP to do model binding, mapping form post fields to a class? Some of my PHP code currently looks like this:
class EntryForm
{
public $FirstName = "";
public $LastName = "";
}
$EntryForm = new EntryForm();
if ($_POST && $_POST["Submit"] == "Submit")
{
$EntryForm->FirstName = trim($_POST["FirstName"]);
$EntryForm->LastName = trim($_POST["LastName"]);
}
Is there anything built-in to a typical PHP install that would do such mapping like you'd find in ASP.NET MVC, or does it require an additional framework?
© Stack Overflow or respective owner