Inserting Multiple Rows with CakePHP 3

One of my many gripes with CakePHP 2 was a lack of multi row inserts. Cake2 did allow saving multiple rows through a single call via saveMany but all this did was issue a bunch of single row inserts which can be really slow when inserting lots of data. To get around this I’d often do some code like this:

Which sucks because I’m not using the framework and I’m also being lazy by not using PDO binded parameters. Cake3 has finally fixed this with the new Query Builder ORM.

The key here is not to issue execute() until after you’ve added all your data via insert(). This will return an instance of the PDOStatement object which inherits all sorts of valueable methods including count() which will give you the total number of rows inserted and errorInfo() for query errors.

Using Google Analytics in your Single Page Web Application

On break the other day I had a thought: “Why not log all activity in our web application with Google Analytics”. These coffee-break thoughts are quite common for me and sometimes they turn out to be more than caffeine-fueled delusion.  Now this is a b2b application and you generally wouldn’t think about such a thing since Google Analytics is used primarily by online marketers and SEOs. Still I think there is value in seeing what pages are browsed most frequently as well as the power to log HTTP Errors. Given that we are a mostly single page AJAX driven application a little extra work had to be done. Here’s how to implement Google Analytics in your own application.

Building a jQuery DataTables Plugin

I like datatables and use it a lot at work. I’ve used datatables so much that I’ve written a CakePHP plugin for it, creatively named CakePHP-Datatables. Documentation on creating plugins is a little rough though. It took me quite some time to write my first one, so I decided to give a little back, and take you through creating a very simple plugin called, My Button. This plugin will add a button to your datatables instance.

Accessing Files Outside of a Chroot Directory

Just recently I needed to provide access to my home system for a remote designer. To prevent the designer from accessing anything else on my server I found this nifty trick. I setup the designer with a user account that has FTP access. I set the home directory as a chroot, and then to get around not being able to add a symbolic link with the home directory I mounted the path to the files. Here’s how I did it using VSFTP.