The front-end of Headless CMS

I wrote a blog on what Headless CMS is all about  on my agency site back in December. Partly to help explain to our clients what this technology is all about, partly to help crystalise some of my thoughts on the subject.

I’m currently embarking on an interesting project to build a set of tools to build a front-end website in PHP based on Headless CMS technology. My aim is to open source this front-end code, though we need to prove it first on a few projects.

I thought I’d blog about my experience and findings here. The following is a short technical focussed intro to all this. Continue reading “The front-end of Headless CMS”

PHP and me

PHP has just reached an incredible milestone, it’s 20 years old! On the 8th June, 1995, Rasmus Lerdorf released PHP 1.0. Now, 20 years later, PHP 7 is on the brink of being released and the language is stronger than its ever been before. With all the #20yearsofPHP stories around the internet I thought I’d add my own experiences and thoughts on how PHP has affected me.
Continue reading “PHP and me”

Checking your Zend Framework route order

The order that you create your routes in Zend Framework is important, with the last route defined in your code being matched first. This allows you to set up custom routes and if these aren’t matched Zend Framework helpfully falls back to the default route which is set up first. If you have a lot of routes though, set up in different places, it can get difficult to verify the order of your routes.

Just use this snippet of code in your controller to return a list of route names set up in your ZF application in the order they are matched via the routing system (i.e. the route at number 1 is matched first, then route 2, etc).

// Output list of routes, in the order they are matched
echo '<ol>';
$routes = array_reverse($this->getFrontController()->getRouter()->getRoutes());
foreach ($routes as $name => $route) {
    echo "	<li>$name</li>\n";
}
echo '</ol>';

Find out more about the ZF Router at the ZF manual.

Finding the Apache user in PHP

In PHP, knowing what the Apache user is on your webserver is very useful. Anything that writes a file to the server for example sessions, uploading files or other temporary file operations, needs to have the destination folder writeable by Apache. If you’re developing locally that’s not usually a problem. But as soon as you’re out in the real world file permission issues can sometimes be a pain.

If you’re having difficulties finding out what the Apache user is try this simple script to help you out.

It basically writes a small temporary file, checks the owner username, gets rid of the file and prints the Apache username to the screen. It should work on PHP4 and PHP5.

$tmpFilename = tempnam('/tmp', 'TEST');
$handle = fopen($tmpFilename, 'w');
fwrite($handle, 'testdata');
fclose($handle);
$info = posix_getpwuid(fileowner($tmpFilename));
$apacheUser = $info['name'];
unlink($tmpFilename);
echo "The Apache user is $apacheUser";

There’s also a small PHP source file you can easily download and use: getApacheUser.phps