Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

fActiveRecord->populate() using an array.

posted by mattsah 8 years ago

So there is this: http://flourishlib.com/discussion/1/439/1370 -- which although would be useful... I would actually prefer if the primary argument to populate() were a custom data array.

In short, rather than using standard request super globals via fRequest, if the parameter is provided it looks for those keys on the provided array making something like the following possible:

$user->populate(array( 'first_name' => 'Matt', 'last_name' => 'Sahagian', 'column...' => 'Value...' ));

This is extremely useful for populating records internally after various forms of processing. It also adds for a nice clean way to add nicely namespaced request parameters that do not fall into the normal populateRelatedRecord() relationship conventions.

$user->populate(fRequest::get('user', 'array'));

Would allow for form inputs with name="user[first_name]" for example... This is a nice simple way to override convention easily.

also might be cool to allow for nested arrays in populateRelatedRecords() as well - as first parameter would be nice for consistency but it would break backwards compatibility with routes unless maybe you check types (array vs. String)

posted by mattsah 8 years ago

I agree that it should be added. I think it is on the todo list. In the meantime I have a snippet that will allow you to do this if you are interested.

posted by unstoppablecarl 8 years ago


For a short time inKWell used an alternative form which had the convention being name="table['column']. Depending on how your snippet works, the issue I ran into was that file uploads and images were pretty dependent on the original convention, so they would break.

There are "hacks" around this, but they're not very clean and require storing the original $_GET, modifying it temporarily during the populate, and then restoring it. This is not the kind of solution I'm looking for. But I'm more than willing to take a look at your solution if it avoids this. Can you pastebin it and post a link?

posted by mattsah 8 years ago

Unfortunately my snippet doesn't come close to your requirements. It doesn't handle file uploads at all.

posted by unstoppablecarl 8 years ago