Warning: The magic method SFML_Singleton::__wakeup() must have public visibility in /home/public/wp-content/plugins/sf-move-login/inc/classes/class-sfml-singleton.php on line 72
cakephp – Thoughts, etc.

Thoughts, etc.

Tracking the occasional random walk

cakephp

Responding to HTTP OPTIONS requests in CakePHP

2017-02-28 / 4 Comments

I recently needed to add  Access-Control-Allow-Origin headers to resources on an API developed with CakePHP. There’s a good description of how to accomplish this from ThinkingMedia in 2015, but it uses DispatcherFilters, which have since been deprecated in favour of Middleware. The $request  and $response objects available to middleware have different interfaces than those retrieved from the event data in the … [Read more…]

Posted in: code Tagged: cakephp

Abstract app controllers and the CakePHP ACL plugin

2016-12-06 / Leave a Comment

I’m working on a CakePHP-based app that has multiple abstract base controller classes that inherit from AppController. The majority of the concrete controllers inherit from one of these abstract classes. I recently added the CakePHP/Acl plugin to the app, and was presented with the error

Shell
1
Exception: Cannot instantiate abstract class App\Controller\MyAbstractController in [/apppath/vendor/cakephp/acl/src/AclExtras.php, line 433]

when I tried to use the  bin/cake acl_extras aco_sync command to generate ACOs … [Read more…]

Posted in: code Tagged: cakephp

Adding many-to-many joins in CakePHP with newEntity

2016-11-26 / Leave a Comment

To allow CakePHP 3 to add entries to many-to-many join tables when creating or patching entities, the names of the associations must be added to the array of accessible concrete properties on the model. The documentation does mention this fact eventually, as a note in the “Patching HasMany and BelongsToMany” section, but not as part of … [Read more…]

Posted in: code Tagged: cakephp, notes

Listing associated IDs during a Controller query in CakePHP 3

2015-04-28 / Leave a Comment

Yesterday I looked into adding a key-value pair such as  "tag_ids": [1, 2, 3] to a JSON object returned by a serialized CakePHP view, for Bookmarks belonging to many Tags. My solution produces the desired result, but involves the execution of a new database query for every bookmark, on top of the one that retrieved the record in the first place. This is not … [Read more…]

Posted in: code Tagged: cakephp

Array of associated IDs in CakePHP 3.0 “belongsToMany” relationship

2015-04-27 / 1 Comment

Today I was struggling with how to get CakePHP to return a JSON representation of a model, including a simple array of the foreign-key ids from the join table that specifies a mutual belongsToMany relationship (formerly, hasAndBelongsToMany or HABTM). For a concrete example, I wanted to build on the Bookmarker tutorial by creating an API endpoint to … [Read more…]

Posted in: code Tagged: cakephp