array_map can take multiple arrays. I like how it starts mapping through them starting at the first element of each array all together and then keeps mapping until it completes the largest array. Each argument to the callback function is the current element of the...
IT Tips
CakePHP 4 – Formatting Validation Errors for use with Flash Messages
I've posted about this before but I think this approach is entirely less complicated Validation errors in CakePHP come in an array similar to the following: $errors = [ 'asn_number' => [ '_empty' => 'ASN cannot be blank', ], 'their_po' => [ '_empty' => 'Their PO...
CakePHP 4 – Rendering an XML view to a variable
Rendering XML to a variable using CakePHP's XmlView class Learnings Instantiating and using ViewBuilderYou don't need ->set() if you pass the data to ->build()You can move XML creation into its own class to clean your controller action up and use it elsewhere in...
Build Complex LIKE Query with CakePHP Query Builder
How to create this MySQL query with CakePHP 4? SET @search = '9233' COLLATE utf8mb4_general_ci; SELECT * FROM 100pbc_new.addresses WHERE trading_partner LIKE CONCAT('%', @search, '%') OR dc_code LIKE CONCAT('%', @search, '%') OR dc_name LIKE CONCAT('%', @search, '%')...
How to get the Google Chrome PDF Viewer to Display Document Page Sizes in Metric
I am in Melbourne Australia and we use metric page sizes. The default display units for the embedded Google Chrome PDF Viewer is inches. How to set Google Chrome to display document properties in Metric Click the three vertical dots menuChoose settingsEnter language...
Chrome file download – Failed Network error
Just had a situation with sending a file to a browser with POST request and it kept erroring with "Failed - Network error" <?php // post request $barcodefile = 'barcode.pdf'; return $response->withFile(TMP . '$barcodefile, ['download' => true, 'name'=>...
Custom Location of cups-pdf denied by apparmor
Apr 25 09:31:23 tgn-vm-wms01 kernel: audit: type=1400 audit(1650879083.060:80): apparmor="DENIED" operation="mknod" profile="/usr/lib/cups/backend/cups-pdf" name="/var/www/tgn/webroot/files/PDF/Test_Page-job_12.pdf" pid=80336 comm="gs" requested_mask="c"...
CakePHP 4 from a sub directory
I have a default Nginx install on Ubuntu 22.04 LTS inside a Docker Container using I want /var/www/html to remain as the root but a CakePHP 4 app to be served as follows requests to hostname.example.com as served from /var/www/html requests to...
Where in the Middlewares should CORS Middleware be placed in CakePHP?
Answer: Before RoutingMiddleware EventManager::instance()->on('Server.buildMiddleware', function ($event, $middleware) { try { $middleware->insertBefore(RoutingMiddleware::class, new CorsMiddleware()); } catch (\LogicException $exception) { $middleware->add(new...
Client Apache Reverse Proxy Cake Token Auth
I have a reverse proxy that protects backend with basic auth client -> basic auth reverse proxy -> token auth cakephp backend curl -v \ -H 'Authorization: Basic base64_encoded_user_pass_here' \ -H 'Authorization: Token cakephptokenhere' \...