adamwathan / form

Super basic form HTML builder, only really exists so I can pull it in for some other more useful projects.
MIT License
232 stars 117 forks source link

Accept array based binding #13

Closed nCrazed closed 10 years ago

nCrazed commented 10 years ago

It would be very convenient if the FormBuilder::bind worked with array as well as objects just like Larave's Form::model.

Let me know if that's a feature you want to include in this library and I'll start working on a PR.

adamwathan commented 10 years ago

Hey thanks for the suggestion. Would just casting the array to an object be enough or do you need to use keys that wouldn't be valid as property names (like keys with hyphens, or starting with numbers, etc.)?

If that will work, could just modify bind to look like this:

    public function bind($model)
    {
        $this->model = is_array($model) ? (object) $model : $model;
    }
nCrazed commented 10 years ago

Yeah, that should be sufficient, thanks.

adamwathan commented 10 years ago

Cool, still feel free to submit that as a PR if you like (with tests of course! :smile: ) and I'll merge it in, or I'll add it in when I get a chance.