BEHAVIORS in yii2

Source: Internet
Author: User
Batch insert Code Yii: $ app-& amp; gt; db-& amp; gt; createCommand ()-& amp; gt; batchInsert ($ rangeDetailModel: tableName (), [& #039; type & #039;, & #039; range_id & #039;, & #039; value & #039;], $ branchArr)-& amp; gt; execute (); to add the following behavior publicfunctionbehaviors (){... batch insert Code

Yii: $ app-> db-> createCommand ()-> batchInsert ($ rangeDetailModel: tableName (), ['type', 'range _ id ', 'value'], $ branchArr)-> execute ();

To add the following actions

Public function behaviors ()

{Return [['class' => BlameableBehavior: className (), 'bubuckets' => [ActiveRecord: EVENT_BEFORE_INSERT => ['create _ by'], ActiveRecord :: EVENT_BEFORE_UPDATE => 'lastupdate _ by'], 'timestamp' => ['class' => 'yii \ behaviors \ TimestampBehavior ', 'bubuckets' => [ActiveRecord :: EVENT_BEFORE_INSERT => ['create _ dt ', 'lastupdate _ dt'], ActiveRecord: EVENT_BEFORE_UPDATE => ['lastupdate _ dt '];} this behavior is used by default in AR, but it won't work if I use BATCHINSERT. I tried to write it like this. Although there is nothing soft to use $ beh ['yii \ behaviors \ BlameableBehavior '] = [ActiveRecord:: EVENT_BEFORE_INSERT => ['create _ by'], ActiveRecord: EVENT_BEFORE_UPDATE => 'lastupdate _ by']; Yii: $ app-> db-> createCommand () -> batchInsert ($ rangeDetailModel: tableName (), ['type', 'range _ id', 'value'], $ are1_r)-> attachBehaviors ($ beh) -> execute ();

Reply content:

Batch insert Code

Yii: $ app-> db-> createCommand ()-> batchInsert ($ rangeDetailModel: tableName (), ['type', 'range _ id ', 'value'], $ branchArr)-> execute ();

To add the following actions

Public function behaviors ()

{Return [['class' => BlameableBehavior: className (), 'bubuckets' => [ActiveRecord: EVENT_BEFORE_INSERT => ['create _ by'], ActiveRecord :: EVENT_BEFORE_UPDATE => 'lastupdate _ by'], 'timestamp' => ['class' => 'yii \ behaviors \ TimestampBehavior ', 'bubuckets' => [ActiveRecord :: EVENT_BEFORE_INSERT => ['create _ dt ', 'lastupdate _ dt'], ActiveRecord: EVENT_BEFORE_UPDATE => ['lastupdate _ dt '];} this behavior is used by default in AR, but it won't work if I use BATCHINSERT. I tried to write it like this. Although there is nothing soft to use $ beh ['yii \ behaviors \ BlameableBehavior '] = [ActiveRecord:: EVENT_BEFORE_INSERT => ['create _ by'], ActiveRecord: EVENT_BEFORE_UPDATE => 'lastupdate _ by']; Yii: $ app-> db-> createCommand () -> batchInsert ($ rangeDetailModel: tableName (), ['type', 'range _ id', 'value'], $ are1_r)-> attachBehaviors ($ beh) -> execute ();

createCommandIt is dao, and it is out of ActiveRecord.

You can simply set the time for your ar.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.