[英]Any support for optimistic locking in CakePHP?

I'm just starting out with CakePHP, and I can't find any support for implementing an optimistic locking scheme. The closest I could find was a comment on this CakePHP blog post saying that it wasn't supported in June 2008.


Does anyone know if that has changed, or if someone has published an extension or a tutorial on how to implement it yourself?


For a description of optimistic locking, see this answer.


3 个解决方案


Not in the Core, and after a quick google it doesn appear that anyone is sharing a behavior if they made one. That would be my suggested tactic.



In the book "Practical CakePHP Projects" on chapter 10 is some code given to make your own "Magic Fields". One of them is a field for optimistic locking. I haven't tried it yet, but it looks quite good actually.

在第10章的“Practical CakePHP Projects”一書中,有一些代碼用於制作你自己的“Magic Fields”。其中一個是樂觀鎖定領域。我還沒試過,但實際上它看起來很不錯。


Tadashi Nakamura has posted an OptimisticLock behaviour on GitHub. It's not quite perfect, because it does the query for the last modified date before writing the changed record. That leaves you open to either silently overwriting another user's changes or hitting a deadlock. When I tried to write a behaviour like this, I wanted to include the last modified date in the update's where clause and fail if the rows affected is zero. At that time, there was no support for adding an extra condition to an update query. I haven't used PHP lately, so I don't know if that has changed.

Tadashi Nakamura在GitHub上發布了一個OptimisticLock行為。它並不完美,因為它在寫入更改的記錄之前對最后修改日期進行查詢。這讓你可以默默地覆蓋其他用戶的更改或者遇到死鎖。當我嘗試編寫這樣的行為時,我想在update的where子句中包含最后修改日期,如果受影響的行為零則失敗。那時,不支持向更新查詢添加額外條件。我最近沒有使用PHP,所以我不知道這是否已經改變。



粤ICP备14056181号  © 2014-2021