Author Archives: Richard Nicol

About Richard Nicol

Developer with experience in many languages and environments.

Creating Custom Routes in Silverstripe 3.1

We wanted to create a Route to our custom Products Controller in our products module for SilverStripe 3.1, such as: “<product-slug>”

However looking at the Controller Documentation it was not clear how to create a route without an Action being supplied. In our example above the action is not specified, as we just want to use ‘view’.


Create a <module-name>/_config/routes.yml file containing the following:

The above will redirect any Url that starts with “/product” to our Product_Controller. Note that everything after the rule, so after “/product”, is used in the next bit for matching.

Now we need to add private static $url_handers to Product_Controller to match our path, so in this example we need to match “$Slug!” which will match “<product-slug>”. Note the ! means the slug is required. Of course we want to direct this to a specific action, in this case “view”, this gives us:

Now just add “view” to the $allow_actions and add the “view” function. This gives the final Product_Controller as follows:

Handy note:

You can put ?debug_request=1 on the end of your URL to see how it determines which Controller to use.

Bookmark and Share

Set up SilverStripe 3.1 using only Git (No Composer)

We recently tried to use composer to set up SilverStripe 3.1, but ended up with a dependency nightmare. In order to work around this we decided to make use of Git submodules.

First set up your Git repository and run:

Next set up a site directory for the code inside your Git repository. Then navigate to SilverStripe Installer in your browser and Download a copy. Extract files, and copy contents to site folder. Now we need to add the CMS and Framework. Navigate in a browser to the Git Hub repositories for CMS and Framework. Now copy the HTTPS clone URL for each project and run the following, to add these as Git sub modules.

Now delete mysite/_config.php and load the site. Follow the normal install instructions displayed and you will have a running version of SilverStripe 3.1

Bookmark and Share

Enabling MYSQL_CLIENT_INTERACTIVE with Doctrine 2 on Rackspace Cloud Database

We recently ran into problem using Doctrine 2 connecting to a Rackspace Cloud Database using the MySqli Driver.


We have a long running PHP script that can sometimes run for hours at a time¬†whilst processing information. This script requires a connection to a database, but has long periods of inactivity where there is no actual interaction with MySQL. By default MySQL uses the “wait_timeout” setting which states, how long an inactive connection can exist before it is killed. This is normally fine with web pages requests, as it is usually a short lived request. Unfortunately you do not have the ability to alter this setting when using Rackspaces Cloud Database.


When using the MySQLi extension you can create a connection in “interactive mode” by passing the “MYSQLI_CLIENT_INTERACTIVE” flag, which will then use the “interactive_timeout” setting. On Rackspace this is set to 8 hours!

Annoyingly Doctrine does not allow you to pass any flags to the MySQLi Connection. So we overrode Doctrine\DBAL\Driver\Connection with our own Driver which then allows us to pass a “flags” parameter through.

Feel free to look at some of the other helpful features in we have added to Doctrine 2 here: ZucchiDoctrine

Bookmark and Share

Better Output for MySQL Select Command Using \G

If you ever find yourself using MySQL via command line and end up with something like this:

mysql-command-line And thought there must be another way, well here it is: Use \G instead of ; at the end of your select command.

For example:

Below is an image of the output from this select:


Happy Querying!


Bookmark and Share

Debug PHP CLI on Remote Server with Xdebug and PHPStorm

This was a head scratcher when I ran into this yesterday and I thought I would share my solution to the following scenario:

I need to debug PHP Command Line script, located on Remote LAMP Virtual WebServer running in Virtual Box with a Shared Folder, using local PHPStorm 5.0.

The solution:

Continue reading “Debug PHP CLI on Remote Server with Xdebug and PHPStorm” »

Bookmark and Share