Say you have OrdersTable associated to CustomersTable, and you want every order you select to automatically contain the corresponding customer information. (So that you don’t have to do ->contain('Customers') on each find() call.) There are two ways to accomplish this. In your OrdersTable: public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary) { $query->contain(‘Customers’); return… Continue reading Containing associated tables automatically
Category: Development
Structuring CakePHP models in subfolders
Say you want to organise your CakePHP models (tables) into subfolders. If you simply move the class into a subfolder, it won’t be picked up automatically. For example, here’s how you can tell the TableLocator to look for OrderStatuses in a specific subfolder Orders under Model/Table. In your controller: First, prepare the shorthand variables. $tableRegistry… Continue reading Structuring CakePHP models in subfolders
Setting up CakePHP CRUD plugin to use tables from another plugin
In the controller where you initialise Crud: $this->loadComponent(‘Crud.Crud’, [ // … ]); $this->Crud->useModel(sprintf( ‘%s.%s’, ‘MyPlugin’, $this->Crud->getController()->defaultTable )); Prevent linking to the plugin where your tables are: /** * Before render callback. * * @param \Cake\Event\Event $event The beforeRender event. * @return void */ public function beforeRender(\Cake\Event\EventInterface $event) { // prevent linking to the table plugin:… Continue reading Setting up CakePHP CRUD plugin to use tables from another plugin
Sending SES complaints and bounces to SQS via SNS
Debugging Amazon SQS not receiving SES bounce and complaint notifications? I hear you. Navigating and figuring out tons of seemingly identical documentation articles written in the wordiest way feels impossible. In short, I got it to work by following this basic scenario: setting up an SNS topic; selecting that topic in Feedback notifications for a… Continue reading Sending SES complaints and bounces to SQS via SNS
Cheapest MySQL database hosting for a hobby project?
If you search for cheapest mysql database, you will get results on Reddit, where the most common advice is to get a Digital Ocean VPS for $5/mo. Cheapest mySQL hosting? Which is the cheapest MySQL hosting in cloud? Cheap database hosting for hobbyist? While $5/mo. is kind of cheap, it’s not the cheapest. Here are… Continue reading Cheapest MySQL database hosting for a hobby project?
nvm, npm, node: Command not found
The problem I had gatsbyjs, node and npm installed on a Debian system. Now I’m getting this error: -bash: gatsby: command not found -bash: node: command not found -bash: npm: command not found Troubleshooting Check npm installation using the package manager: apt-cache policy npm npm: Installed: (none) Check nvm installation: nvm –version 0.39.3 This means… Continue reading nvm, npm, node: Command not found
Persistent ZPL commands that set default values for subsequent fields
Here are the most common or widely used ZPL commands that have a lasting effect on the fields or actions that follow them; they continue to affect subsequent fields or actions until they are explicitly overwritten or the label format ends. ^BY: Sets default values for the width of the narrow bar, the width ratio… Continue reading Persistent ZPL commands that set default values for subsequent fields
Add nvm-managed node to $PATH in init.d or crontab
When I was using node installed via apt-get, a simple NODE=$(which node) was enough. However, once I switched to the nvm-based node, it was no longer installed in one of the $PATH locations where the system is looking. So the correct path had to be added manually. One option is to hardcode whatever the current… Continue reading Add nvm-managed node to $PATH in init.d or crontab
creating-an-api-resource-in-cakephp-4
Post moved to https://faxmodem.eu/blog/development/cakephp/create-rest-api-resource/
cakephp-4-missing-or-incorrect-csrf-cookie-type
Post moved to https://faxmodem.eu/blog/development/cakephp/missing-incorrect-csrf-cookie-type/