1
votes

I'd like to insert data into a mysql table using 'the cakephp way'.

I have a multi-stage program that stores data to a session, and toward the end of the program I'd like to write the session data to the database. I could do this using a standard sql insert statement but would like to know how this should be done using cakephp. (Most of the cakephp doc discusses sending data from a webform, and I'd like to manually submit session data.)

Should I manually format the session data in this format and then send this to the model? And if so, is there a helper function for this?

Array
(
    [ModelName] => Array
        (
            [fieldname1] => 'value'
            [fieldname2] => 'value'
        )
)
1

1 Answers

2
votes

Yes, that's the way to do it. There's really no need for a helper function, just use the ones you normally would.

$name = 'Foo';
$city = 'Bar';

$this->ModelName->save( 
    array(
        'name' => $name,
        'city' => $city
    )
);