[eluser]TaylorOtwell[/eluser]
[quote author="Phil Sturgeon" date="1291242331"]How do you order POST?[/quote]
Not sure what you mean. It may be easier to just post some more code. Also, sorry if "model binding" is slightly confusing terminology in the CI world. That is what the term for this is called in the ASP.NET world. It really has nothing to do with "Models" in the CI sense of the word.
In core/CodeIgniter.php, I call the controller method like this:
Code:
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$MBIND =& load_class('Model_binding', 'core');
call_user_func_array(array(&$CI, $method), $MBIND->bind_post_data($class, $method));
}
else
{
call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
}
The "Model_binding" class lives in system/core. It reflects into the class and method that I pass it and examines the method parameters. If the parameter is not type-hinted then it just looks for a variable in $CI->input->post that matches the parameter name. If it finds one, it adds it to its array of data to pass into the controller method.
Things are slightly more complex if the parameter is type hinted. For example, let's our controller function looks like this:
Code:
public function do_login(User $user)
{
// Do login stuff
}
And, let's say our "User" object looks like this:
Code:
class User {
public $email;
public $password;
}
In this case, the "Model binder" will see that the method requires a "User" type. So, it will instantiate a new User and get the object_vars on the instance. Then, it will map any POST data that has a name matching a property on the User object. After it maps everything, it adds the User instance to the array of parameters to pass into the method.
Let me know if that doesn't make sense!