Apache Sites Enabled Configuration Tricks

Link to htaccess file instead of rewriting rules in configuration file

Within your sites-enabled configurations for apache you can link directly to htaccess files. This allows you to disable htaccess overrides for performance, while still being able to use htaccess files.

 

Redirect inside your apache configuration

You can set redirects directly inside your site configuration file.

 

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.