Just came across a Youtube talk "Iterators in PHP" by Jake Smith published in 2014 that steps through the many different Iterators and some practical examples. I have reproduced many of the examples Jake used below, running them with PHP 8.1.5 and published the code...
IT Tips
PHP array_map Multiple Arrays
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...
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',...
CakePHP 4 – Rendering an XML view to a variable
Rendering XML to a variable using CakePHP's XmlView class Learnings Instantiating and using ViewBuilder You 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...
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,...
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 menu Choose settings Enter 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,...
Custom Location of cups-pdf Out Directory denied by apparmor
# /var/log/syslog 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"...
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) {...
