tags:

views:

71

answers:

1

Hi,

I am having a doubt in my application. In my application i m designing like a Form builder using CakePHP and JQUery and MYSQL.

In my design page, i am designing the Form and on clicking the Save Form button below all my fields i have created, i am saving the Fields by first creating an entry in my Form Table which has(id, name,created_by) and i am retrieving that recently added Form id and i am making use of it to save all my fields in my attributes Table which has(id,form_id,fieldname,type,size,sequence_no,instructions)

But now i felt that getting the recent added id and saving the FIelds using that is like Hard coding or like some wrong way of doing..

What will be the Best way like when i can save the Form and get its id and to use it to my attributes table..

I thought to make use of session variable for storing my form id in it while saving the Form and to read its value while saving the fields in the Attributes Table. Also that even if i make use of that session variable i want keep this FOrm id to be there in the session only in the design page and not anywhere else..

Please suggest me..

+1  A: 

If you are saving related model data, I suggest using the Model::saveAll() method, as it allows you to save everything in one go and also automatically fills in the foreign_key for the related models.

These two book posts might be useful in such a case: http://book.cakephp.org/view/84/Saving-Related-Model-Data-hasOne-hasMany-belongsTo http://book.cakephp.org/view/85/Saving-Related-Model-Data-HABTM

savant