开发者

Insert data in selected columns

I am using cakephp with php, I have table with field id having data type auto number.

In my form I do not have any field with id that's why it sets blank in my model and when I tries to sav开发者_如何学Pythone data it gives error.

how can I insert data into selected columns using model in cakephp?


When you pull the form data, make sure you are using an array with the model name and field names. For example, if you are saving a book to the book model, the array would look something like:

$data['Book']['name'] = 'Title of Book';
$data['Book']['author'] = 'Name of Author';
$data['Book']['pages'] = 205; // number of pages

Then when you save the data, you must call create, then save:

$this->Book->create();
$this->Book->save($data);

This will automatically add the ID (whether auto-increment or UUID) and save the new record.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜