![]() |
Model temporarily switchCallback function - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29) +--- Thread: Model temporarily switchCallback function (/showthread.php?tid=81956) |
Model temporarily switchCallback function - muratdemrel - 05-26-2022 Sometimes we need to create more than one callback functions in a model and change it by situation. For example, i have a recursive chained data as menu with fields id, parentId and title. when i need to create recursive menu array, i'll request for items which parentId is null and import child items on them with afterFind callback, but when i need to create breadcrumb, i'll request current menu item with id and import parents to data with afterFind callback. It would be great if there's a callback switch option instead of allow or disallow all callbacks. I wrote the ugly code below in my model for now but for the future projects it'd be great to have a callback switch function. Thanks. PHP Code: protected $afterFind = ['includeParentData']; |