Yii Framework 2 : Insert Query

save() OR insert()

$model = new User;
$model->name = 'YII';
$model->email = 'yii2@framework.com';
$model->save();  // equivalent to $model->insert();

insert() command

                        'name' => 'yii',
                        'status' => 1,


Insert multiple rows at once using batchInsert() function.

                    ['name', 'status'],
                        ['Bala', 1],
                        ['Akilan', 0],
                        ['Babu', 1],

  • someone

    how to move data from one table to another by using clickable button?help me plsss

  • Anil Kumar Verma

    Behaviors are not working with batch insert.
    But when I use save() then behaviours working fine.
    Please help.

    • Soju Thomas

      behaviours works only for active records.

  • Николай Зуев


  • Hema

    I am using save() function. It is working for some record but not for all. Could you please help me to print insert query to troubleshoot this issue?

  • Tanushree

    I want to use batchInsert using Active Records. I don’t want to use row sql or createCommand. Please help me in this.