Archive

Posts Tagged ‘php’

Zend Framework Quickstart Tutorial: Deploy to a subdirectory instead of web root

November 18th, 2008

When you’re just evaluating something new you do not want to rearrange your whole world just to try something out.

I wanted to try out the Zend Framework and the “QuickStart” tutorial looked very official and the ideal place to start.

However they assume installation is in the webroot. Sorry, but I have other, more important, stuff running on this server and I’m not shoving it aside just for a quick tutorial.

Try as I might, I had great difficulty getting this tutorial to run in a subdirectory. As I’m learning the thing I’ve no idea how to tweak it yet!

Anyway my web root is “/var/www” and I want to put the quickstart tutorial at “/var/www/QuickStart”, which in turn means the public directory is at “/var/www/QuickStart/public”. To make the whole thing work required three changes:

1. Redirect everything to the index in the subdirectory

When I use the cited .htaccess from the tutorial page titled “Create a Rewrite Rule” and call the index it works! Great, except that’s not the test for ‘working’.

Zend needs to feed all requests through the index page so it can farm them out to controllers. The controllers are identified by the ‘filename’ of the request: so the redirection is supposed to catch all the 404′s and feed them into the index. It’s not working until you can call non-existent URL’s without the webserver giving you a 404. eg: “http://servername/QuickStart/public/asdf” should show the “Hello, Zend Framework!” message.

Stay on this step until you get the “Hello” message for made up url under your public directory. E.g. “http://servername/QuickStart/public/asdf”.

My /QuickStart/public/.htaccess became (NB: this is Case Sensitive)


RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /QuickStart/public/index.php [NC,L]

This might be done more cleanly with a “RewriteBase” but this worked so I moved on.

2. Set the “BaseURL” of the front controller

Now there is something not right in the Tutorial because the next checkpoint screenshots a message which doesn’t appear in the code so far displayed. That in itself is very frustrating and entire problem of its own so lets not get distracted. I tried to run through the tutorial again from scratch so I could make this post straight from a fresh run through. But not to be.

If you manage to overcome and reach the next checkpoint you’ll need this:

Add a line to “Step 3″ of the the /application/bootstrap.php to set the base url:


// Step 3: CONTROLLER DIRECTORY SETUP - Point the front controller to your action
// controller directory.
$frontController->setControllerDirectory(APPLICATION_PATH . '/controllers');
$frontController->setBaseUrl('/QuickStart/public');

This tells the front controller to prepend Url’s with the subdirectory, and this got me most of the way through the QuickStart tutorial with one exception.

3. Fix the “Action” in guestbook form

When you post to the guestbook you’ll get an error looking for a file “/guestbook/sign” which doesn’t exist. The form is created with that action and you need to fix it in the GuestbookController.php:

Change the setAction in function _getGuestbookForm() to


$form->setAction($this->_request->getBaseUrl() . $this->_helper->url('sign'));

And with that it should generate a form action “/QuickStart/public/guestbook/sign”.

I’m told this last issue has been lodged has a defect and not necessary from releases “1.7″ and beyond. The helper->url will henceforth prepend the baseUrl to its result.

Zend Framework QuickStart Tutorial: What are the filenames?

November 13th, 2008

I’ve just worked my way through the Tutorial for the PHP Zend Framework. I overlooked downloading the code at the start and launched straight into it creating each piece myself from the tutorial.

After the first couple of pages they (currently) neglect to mention where each piece of code is supposed to go. Maybe I learnt a lot more, but it did not make for a very ‘quick’ start trying to work out where things go from the error messages.

Here’s the final structure of the QuickStart Tutorial…


application/
|-- app.ini
|-- bootstrap.php
|-- controllers
|   |-- ErrorController.php
|   |-- GuestbookController.php
|   `-- IndexController.php
|-- forms
|   `-- GuestBook.php
|-- layouts
|   `-- scripts
|       `-- layout.phtml
|-- models
|   |-- DbTable
|   |   `-- GuestBook.php
|   `-- GuestBook.php
`-- views
    `-- scripts
        |-- error
        |   `-- error.phtml
        |-- guestbook
        |   |-- index.phtml
        |   `-- sign.phtml
        `-- index
            `-- index.phtml

Photo Galleria

February 15th, 2008

I decided to create a photo gallery to

  1. show off the best of my old travel photos, and
  2. to quickly and routinely share new photos with friends after events

The requirements evolved to

  1. display long captions – to tell the story
  2. arbitrarily sorted presentation – to tell the story
  3. drop images into a directory and we’re done – quick

In the past I’ve cobbled together solutions, a favourite of which is to put all the photos into a directory, create a text file of captions, create an html template file, and finally run a hand-built perl script over it which generates a static html gallery. Two complaints with this is that my html templates are very plain – I’m no graphic designer – and I can never find the perl script again – or don’t have a perl installation handy. It just doesn’t work out very often. So I’ve gone wandering with my latest favourite problem solving methodology: what do the non-programmers do?

A wander of the web and you find people doing some very pretty things using a variety of technologies.
There is a good list of options here that I worked through.

There were also a few using script.aculo.us which I can’t be bothering finding again. These libraries demonstrate how far AJAX has come. I find it intimidating to discover how fast we must all run to keep up with the pace of developments these days.

I seriously considered digging out my scripts and prettying up the html template with some of the CSSPlay ideas, but then the amount of development effort involved stopped and reminded myself of the methodology: what do the non-programmers do?

I dug around for some polished gallery applications a couple of months ago and just couldn’t find anything impressive. This time Zenphoto emerged. It meets all the requirements. It’s more polished than WordPress. Needs php and mysql. You can skin it with any of the eye candy solutions above. And the code is beautifully clean. I’ve immediately been able to start tweaking it to suit myself! Thumbs up. You know you’ve found something you like when you spend hours trying all the different colors and options.

Wanna see my slides?!!? :-)
Photos from ‘the big trip’ around Canada and the USA