Inserting multiple items into a database table

I’m trying to save multiple records using the active record in Yii :

In my application, the user fills out ‘n’ number of items on the frontend. Each of these items should be then stored into the item model.

foreach($items as $item)


    $model = new Item;

    $model->name = $item['name'];



Is creating a new object for the Item class required for each iteration ? AM i doing this correctly ? or is there a better way ?

This looks fine and yes instantiating of new object for a new record is necessary.

The topic Working with Forms: Collecting Tabular Input from the guide maybe could also help you.

There are also a lot of topics about this here in the forum.