views:

185

answers:

0

Already developed few websites on top of CakePHP but now ran into a brick wall. To make things simple, here's the scenario:

Database Schema:

USERS
 - id
 - name

RECORDS
 - id
 - user_id
 - timestamp

RECORD_FIELDS
 - id
 - name

RECORD_DATA
 - id
 - record_id
 - record_field_id
 - value

Basically it's an control panel for staff that will store/keep track of different records for our members. Different records have different required fields, thus the RECORD_FIELDS table to store all possible form fields and RECORD_DATA to store all field values.

I've been spinning wheels without making any progress for quite some time now. Here's where I'm at right now:

controllers/records_controller.php:

function add(){
    $this->set('fields', $this->Record->RecordField->find('list'));

    if(!empty($this->data)) {
        $this->Record->saveAll($this->data);
    }
}

views/records/add.ctp:

echo $form->create();
foreach($fields as $id => $name){
    echo $form->input("RecordField.$id", array('label'=>$name));
}
echo $form->end('Add');

Obviously I simplified the above but that's just as far as I could go. I also tried HABTM, which I did get to work somehow but that didn't let to save submitted values to separate table. Any idea how to get these variable form fields properly displayed and get their submitted values saved in RECORD_DATA table accordingly?

Thanks for all the help!