Upgrade time

26th February 2007

Just a quick note to warn you that the server that akrabat.com runs on is going to be upgraded tomorrow, so expect serious downtime as we see what happens when you go from FC-old to FC6 !

All should be back up and running by the evening though!

PHP UK Conference 2007

24th February 2007

PHP Conference Logo
I've just come back from the PHP UK Conference (2007) held in London. It was a one day event with five speakers. I took a few photos, but most didn't come out too well as ISO 400 sucks on my camera!

Cal Evans introduced us to mash ups and the pain of getting an API key from UPS! Simon Laws talked about SCA which was new to me and I thought it was a very clever idea. Kevlin Henney gave us a tour of the core ideas in Object Orientation which was fascinating and eye opening. Rasmus gave us a whistle stop tutorial on performance, security and PHP5 and then the day ended with a discussion on the design of interactive systems for everyday life by Bill Gaver.

I met up with people from the West Midlands PHP User Group; All of Pale Purple were down and I also met up with Darren from Siftware and Greg from Senokian. I also got to "network" and spoke to people from Zend, Yahoo! and a dozen other companies!

It was also great to meet Dagfinn Reiersøl who has just finished writing PHP in Action which looks to be an excellent book for the intermediate to advanced PHP developer. (Disclaimer: I'm currently writing a book for Manning, so I could be biased…) I first came across Dagfinn on the PHP Application Design forum on Sitepoint where his posts are always informative and worth reading. There are so few books out there that are aimed at those of us that already know PHP, that PHP in Action should do very well. Chapter 1 is a free download from Manning's website and part 1 of chapter 7 is available from the Zend Devzone. Check it out!

If you didn't go to the UK PHP Conference this year, make sure that you go next year!

Indonesian Translation of the Tutorial

11th February 2007

Riki Risnandar has done some sterling work and translated the tuorial to Indonesian! Thank you very much Riki!

You can download the PDF directly and it is also listed on the main tutorial page.

Zend Framework Tutorial for 0.7

11th February 2007

Just a quick update to let you know that version 1.2.x of my Zend Framework Tutorial does actually work on version 0.7 of the framework with no changes. This is because the public API for the MVC components in 0.7 are backwards compatible with 0.6.

I expect that from now on, the basic API for the MVC will stay the same. More advanced stuff, like the module support might change though.

Modules

3rd February 2007

One of the new features to hit the Zend Framework since 0.7 is Zend_Controller_ModuleRouter and its sibling Zend_Controller_ModuleRewriteRouter. This allows for separating out sets of controlers, models and views into their own modules. The directory structure then looks like:

application/
    controllers/
        IndexController.php
        ArticleController.php
    blog/
        controllers/
            IndexController.php
        models/
        views/
    news/
        controllers/
            IndexController.php
            ListController.php
        models/
        views/
    models/
    views/
lib/
    Zend/
webroot/
	css/
	img/
	js/
	index.php

To set this up, you use this code in index.php:


$frontController->setControllerDirectory(array( 
      'default' => array('../application/controllers'), 
      'blog'    => '../application/blog/controllers', 
      'news'    => '../application/news/controllers' 
)); 
$frontController->setRouter(new Zend_Controller_ModuleRouter()) 
      ->setDispatcher(new Zend_Controller_ModuleDispatcher()) 

The module router then maps the first parameter of the URL to the module and so then looks for a controller within that module's controllers directory. Hence http://www.example.com/news/list/recent will map to the News_ListController::recentAction() in the ../application/news/controllers directory. If the first parameter is not a named module, then the default module is used and the first parameter is considered to be the controller instead. In this case http://www.example.com/article/list will map to ArticleController::listAction() in the ../application/controllers directory.

It's all very clever.

One issue with the directory layout above is that the controllers within the default route will need models and views too. These are within the application directory itself an so interspersed with the module directories; feels a bit untidy to me. It makes more sense to me to create a directory called default to hold the three directories:

application/
    blog/
        controllers/
            IndexController.php
        models/
        views/
    default/
        controllers/
            IndexController.php
            ArticleController.php
        models/
        views/
    news/
        controllers/
            IndexController.php
            ListController.php
        models/
        views/
lib/
    Zend/
webroot/
	css/
	img/
	js/
	index.php

with the set up code in index.php becoming:
To set this up, you use this code in index.php:


$frontController->setControllerDirectory(array( 
      'default' => array('../application/default/controllers'), 
      'blog'    => '../application/blog/controllers', 
      'news'    => '../application/news/controllers' 
)); 
$frontController->setRouter(new Zend_Controller_ModuleRouter()) 
      ->setDispatcher(new Zend_Controller_ModuleDispatcher()) 

This now nicely keeps the MVC componts together and seems to work quite well. What I'm not sure of is how to handle an admin site. I suspect that the rewrite module router is the way to do this. I'm now into guesswork though, so will have to actually write some code in my IDE and see what happens.
I'm not sure what directory structure I want yet either.
If we take the news module:

    news/
        controllers/
            IndexController.php
            ListController.php
        models/
        views/

Do I want to put admin with it?

    news/
        controllers/
            admin/
                IndexController.php
            IndexController.php
            ListController.php
        models/
        views/
            admin/

Or do I want a separate adminNews module? It's likely that the models used by news and adminNews will be the same (or adminNews will use a super-set of the news model), so I can see the logic of putting the admin code within the same set of directories.

Maybe I think too much about these sort of issues!