yii\db\BaseActiveRecord::optimisticLock PHP 메소드

optimisticLock() 공개 메소드

Optimistic locking allows multiple users to access the same record for edits and avoids potential conflicts. In case when a user attempts to save the record upon some staled data (because another user has modified the data), a [[StaleObjectException]] exception will be thrown, and the update or deletion is skipped. Optimistic locking is only supported by BaseActiveRecord::update and BaseActiveRecord::delete. To use Optimistic locking: 1. Create a column to store the version number of each row. The column type should be BIGINT DEFAULT 0. Override this method to return the name of this column. 2. Add a required validation rule for the version column to ensure the version value is submitted. 3. In the Web form that collects the user input, add a hidden field that stores the lock version of the recording being updated. 4. In the controller action that does the data updating, try to catch the [[StaleObjectException]] and implement necessary business logic (e.g. merging the changes, prompting stated data) to resolve the conflict.
public optimisticLock ( ) : string
리턴 string the column name that stores the lock version of a table row. If `null` is returned (default implemented), optimistic locking will not be supported.
    public function optimisticLock()
    {
        return null;
    }