PHP Team Development (book)

Book coverThe other day I had a new book sent to me called PHP Team Development, written by Samisa Abeysinghe and published by Packt Publishing. Unfortunately, it arrived at work when I was on holiday so I haven’t been able to have a look at it yet. :-/ However, I’m back today and have the book in my hands (well, not literally, of course, else typing would be much more difficult), so am looking forward to diving in to it.

Hopefully have a bit of a review posted up here some time soon!

Did you like this? Share it:

Shorten urls automatically with a Zend Framework filter

I think we can all agree that URL shortening services are great and are very handy to tidy up those long and obnoxious links. However, a lot of the time people simply forget to use them, or often don’t know about them in the first place. I’ve noticed this in a blog system I wrote using Zend Framework. On one hand I love that people post messages, but on the other it annoys me that they may supply a link that is so long it breaks the formatting of the page, or looks just plain ugly.

So what are my options? I could train everyone who posts blogs on the system to use a url shortening service or I could manually tweak all the links myself. As solutions they are not very practical at all; I don’t have the time to change any/all links myself, and I certainly don’t have enough patience to train everyone! So an automatic way of doing things is needed, and the filtering in Zend Framework comes to the rescue!

Continue reading “Shorten urls automatically with a Zend Framework filter”

Did you like this? Share it:

Quick and easy email encoding view helper

Here’s a quick and easy view helper for Zend Framework that will encode an email address. It will encode just an email address or return a whole mailto link. The encoding is basically the same as in the Smarty template engine.

Obviously there’s a lot of room for improvement; javascript encoding, representation as an image, and so on… but then it wouldn’t be quick an easy – it’d be slightly longer and just a little more complex. 😉

Continue reading “Quick and easy email encoding view helper”

Did you like this? Share it:

Auto generating basic models for a Zend Framework app

Do you have a database with foreign keys and just wish you could have something automatically create your ZF models from it? Well, today that was me. So as a little proof of concept, this is the code I came up with to do it for me…

But before we get to that, a few caveats:

  • It’s just a proof of concept
  • The output needs updating for proper reference names, etc.
  • Outputs everything to screen in one go and doesn’t save the files.

However, it might be handy to someone, so I post it up for your comments.
Continue reading “Auto generating basic models for a Zend Framework app”

Did you like this? Share it:

Zend Framework 1.5 preview release

For those that don’t know by now, version 1.5 of the Zend Framework is now out in preview release. Congratulations to everyone who has had apart in getting out this release – from programmers to documentation writers to project managers!

There are a lot of very interesting updates and new features. Some notable ones are the inclusion of Zend_Form, Zend_Layout, OpenID and LDAP adapters for authentication, Technorati web service, as well has handy tweaks Zend_Db_Table such as being able to directly access the select object.

As it’s a preview release the code isn’t intended for production systems just yet, though I hope the time frame for getting it to stable release is short enough so that I can use it soon, but long enough to work out any major kinks. 😉

Did you like this? Share it:

Force a file download

Here’s a small function that will allow you to force a file download.

/**
 * Force a file download via HTTP.
 *
 * File is required to be on the same server and accessible via a path.
 * If the file cannot be found or some other error occurs then a
 * '204 No content' header is sent.
 *
 * @param string $path Path and file name
 * @param string $name Name of file when saved on user's computer,
 *                     null for basename from path
 * @param string $type Content type header info (e.g., 'application/vnd.ms-excel')
 * @return void
 * @access public
 */
/* public static */ function download($path, $name = null, $type = 'binary/octet-stream')
{
    if (headers_sent()) {
        echo 'File download failure: HTTP headers have already been sent and cannot be changed.';
        exit;
    }
    
    $path = realpath($path);
    if ($path === false || !is_file($path) || !is_readable($path)) {
        header('HTTP/1.0 204 No Content');
        exit;
    }

    $name = (empty($name)) ? basename($path) : $name;
    $size = filesize($path);

    header('Expires: Mon, 20 May 1974 23:58:00 GMT');
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
    header('Cache-Control: no-store, no-cache, must-revalidate');
    header('Cache-Control: post-check=0, pre-check=0', false);
    header('Cache-Control: private');
    header('Pragma: no-cache');
    header("Content-Transfer-Encoding: binary");
    header("Content-type: {$type}");
    header("Content-length: {$size}");
    header("Content-disposition: attachment; filename=\"{$name}\"");
    readfile($path);
    exit;
}

Very easy to use, too! Here are some examples of how you might call the function:

download('./myfile.txt');

download(__FILE__, 'a file for you.php');

download('/home/you/files/spreadsheet.xml', 'ssheet_' . date('Ymd'), 'application/vnd.ms-excel');
Did you like this? Share it:

Zend Certified Engineer

During the php|works conference in Atlanta this year I took the PHP5 Zend Certification, and I’m pleased to say that today I found out I had passed! So I am now pleased to say that I am a Zend Certified Engineer for both PHP4 and PHP5.

And just to prove it…

Did you like this? Share it:

Simple image view helper for Zend Framework

Here’s a simply view helper for the Zend Framework that can be used to display image tags. It checks to see if the image file exists and if not then it’ll use the data url scheme to output a very simple image that, ironically, says ‘NO IMG’ on it. 🙂 Please note, though, that I’ve only seen Firefox support this scheme, as wonderful as it is!

Continue reading “Simple image view helper for Zend Framework”

Did you like this? Share it: