Customizing CakePHP 3 Form Helper

The Cake 3 form helper component’s default output isn’t super conducive to working with front-end frameworks like Bootstrap. Luckily the Cake 3 team provide us with a template system to change the default output. Here’s a quick example to get you going:

The above sample outputs the following HTML:

The Cake 3 template system is quite extensive, check it out.

Multiple Checkboxes and CakePHP3 CSRF Security Component

I’ve spent a bit of time over the last few months learning Cake 3 (currently RC-2). I’ve been having a heck of a time with the CSRF Component barking at me that my requests have been black holed. If you’ve used the CSRF at all you’ve no doubt received something like this:

The request has been black-holed Error: The requested address ‘/controller/action/1′ was not found on this server.

Well I finally figured it out. When dealing with multiple checkboxes to submit an array over HTTP POST, you will want to use the unlockField feature. The component clearly has problems with creating a hash from multiple checkbox elements with the same name. Here’s some example code to get you out of the black hole.


Sorting on Associated Models with the CakePHP3 Paginator Component

I was a bit stumped recently while attempting to sort on associated models using Cake 3’s paginator component. It would only sort on main models fields. After finally reading through ALL of the documentation I stumbled upon the “sortWhiteList” option. Cake makes you use this in order to sort on associated models. Say we have a Cities model, which has associations to a Counties and States model. To sort on the and field we would use the following configuration:

Now inside the PaginatorHelper these can be referenced as follows:


Vendors, Packagist, and Composer in CakePHP 3

New with CakePHP 3 is the recommended use of composer. Composer makes managing dependencies easier and updating packages easier as well. Packagist is a nice resource for finding packages, but I do think it could use a bit more work such as a comment system for packages. I had some difficulties at first adding packages using composer and getting them to load in my Cake3 project. I’ll break down two examples in this blog post so you can get up and running faster.

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.