Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kaihiro/optimistic-lock
Optimistic Lock for CakePHP3
https://github.com/kaihiro/optimistic-lock
Last synced: 3 days ago
JSON representation
Optimistic Lock for CakePHP3
- Host: GitHub
- URL: https://github.com/kaihiro/optimistic-lock
- Owner: kaihiro
- Created: 2016-12-06T12:45:02.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-13T00:56:06.000Z (over 7 years ago)
- Last Synced: 2024-09-19T03:16:44.304Z (about 2 months ago)
- Language: PHP
- Size: 7.81 KB
- Stars: 2
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# OptimisticLock plugin for CakePHP3
## Installation
You can install this plugin into your CakePHP application using [composer](http://getcomposer.org).
The recommended way to install composer packages is:
```
composer require kaihiro/optimistic-lock
```## Usage
### Table
```
addBehavior('OptimisticLock.OptimisticLock');
}
}
```### FormHelper
```
Posts->get($id);if ($this->request->is(['patch', 'post', 'put'])) {
try {
$post = $this->Posts->patchEntity($post, $this->request->data);
if ($this-> Posts->save($post)) {
$this->Flash->success(__('The post result has been saved.'));return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The post could not be saved. Please, try again.'));
}// You can handle optimistic lock by catching OptimisticLockException.
} catch (OptimisticLockException $e) {
$this->Flash->error(__('optimistic lock error.'));
}
}
$this->set(compact('post'));
$this->set('_serialize', ['post']);
}
```