Search code examples
zend-frameworkzend-formzend-db

Saving Model to multiple tables


maybe on of you can help my with a little problem im dealing with right now.

I have a simple form with: Loginname, Loginpassword, Name, Firstname, Age. Now i want to save these information in two different tables. Users and UserInfo.

I have a model "user" that holds the login information. Now i want to save the additional data in the other database-table.

The user information is always linked to the normal user.

My thinking was, to store all the information in one big "user model" and upon $model->save() storing the data in the relating tables.

Especially when using the model in different modules it would be helpful to do all the magic in the model and not the controller.

Thanks in advance!


Solution

  • I think what you want todo is create a model mapper for handling your users data that will reference both your table models.

    There is a good example here:

    Multiple Tables for a single Model using Zend_Model_Mappers and Zend_Db_Table_Abstract