简体   繁体   中英

CakePHP 3 - Event on Model->link(…)

I am working on an application management panel, with Users and Apps . I would like to log the changes (add / edit / delete) to both Apps and Users. This I realised using a custom Behavior, using the afterSave() and afterDelete() callbacks.

Note that Apps hasMany Users and Users hasMany Apps, with a apps_users join table. I created models for Apps and Users .

However, I would also like to log the links between Apps and Users (the permissions). When permissions are given, a link between a user and an app is created using Apps->Users->link($app, [$user]) .

Question: How to attach an callback to a $...->link(...) call?

As far as I can tell there is not regular callback for it, like there is for save() and delete()

Browsing my own questions when I noticed this.

The solution would be to create table objects for the link table and add afterSave and afterDelete events for those tables. A behaviour could be created that is attached to those link table objects to reuse the logic.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM