Yii2.0 Database Model Tutorials

Yii Framework 2 : Upsert Query

Upsert is an atomic operation. `Upsert()` will insert new record into a database table If table do not already exist or update them. upsert( $table, $insertColumns, $updateColumns = true, $params = []) Using QueryBuilder $sql = $queryBuilder->upsert('pages', [ 'name' => 'Home page', 'url' => 'http://bsourcecode.com/', // url is unique 'visits' => 10000, ], [ 'visits' => new \yii\db\Expression('visits + 1'), ], $params = array()); Using Command: Yii::$app->db->createCommand()->upsert('pages', [ 'name' => […]... Read More »

Yii Framework 2 : Scenarios

Yii2.0 framework model is designed in very comfortable way for dynamic logic based on scenario. In this tutorial i will share my experience about Scenarios. A model may be used in different scenarios in different business rules and logic.... Read More »