php - How to implement mysql record locking in Yii2 -


i want implement record locking functionality in yii2 application.

if 1 user opens update link/record (ex.http://localhost/myproject/backend/web/user/update/1) user cannot able access thislink , user alert message saying "this record opened user". record/page should lock user. (same ms excel locking)

once first user finishes , leaves record/page should unlock , user can read/update data.

so how can use mysql database locking mechanism here in yii2 active records or there other way implement this.

any appreciated.

it's called optimistic locking , described in official docs. here example of implementation:

// ------ view code -------  use yii\helpers\html;  // ...other input fields echo html::activehiddeninput($model, 'version');   // ------ controller code -------  use yii\db\staleobjectexception;  public function actionupdate($id) {     $model = $this->findmodel($id);      try {         if ($model->load(yii::$app->request->post()) && $model->save()) {             return $this->redirect(['view', 'id' => $model->id]);         } else {             return $this->render('update', [                 'model' => $model,             ]);         }     } catch (staleobjectexception $e) {         // logic resolve conflict     } } 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -