Day Camp for Developers virtual conference

1st September 2010

My friend Cal Evans is putting on a virtual conference called Day Camp 4 Developers. The most interesting thing about this conference is that it is about the "soft skills" that you need as a developer. There are many conferences that deal withe the technical skills improvements that you need, but less that handle the rest of your job, so this piqued my interest.

It's a one day tech-agnostic conference containing 5 sessions and all you need is an Internet connection. Good choice of speakers too: Josh Holmes, Elizabeth Naramore, Scott Gordon, Brian Prince and Lorna Mitchell.

Details

Date: Saturday, November 6th
Price: $35 per person ($30 in groups of 10 or more)
Where: On-Line (gotowebinar.com)

What's also cool is that all sessions will be recorded and available for you to review at your leisure. Of course, if you're busy that day, then you can buy a ticket and get the videos anyway to listen to at a later date. Apparently, you'll be able to buy the session recordings after the event, but at a price premium, so probaly worth just getting a ticket and not (virtually!) turning up on the day :)

You can buy a ticket directly via eventbrite now and be sure of your place!

The Redirector action helper

30th August 2010

Following on from the discussion on the FlashMessenger action helper, I thought I'd also cover another supplied helper: Redirector.

Redirector does what it says on the tin and redirects the user to another page. I mostly use this when coming back from filling a form in, so that the user is then redirected to another page. In admin systems, this is usually a list page. On front end websites, this is usually a thank you page. Though for log-in forms, I tend to try and return the user to where they were going!

It's used in a controller action method like this:

$urlOptions = array('controller'=>'index''action'=>'index');
$this->_helper->redirector->gotoRoute($urlOptions);

gotoRoute() takes the same set of parameters are the url() view helper which is not a surprise as they both proxy through to the Front Controller's router object. It's handy though as one you know one, you know the other :)

If you are using the default route, then you can use gotoSimple(). For example to redirect to the news controller's list action, you would do:

$this->_helper->redirector->gotoSimple('list''news');

The gotoSimple() method signature is:

gotoSimple($action$controller null$module null, array $params = array());

As you can see, it provides defaults for the controller and module and params parameters so you only need to set them if you need to. This works well for admin system as I tend to be redirecting within the same controller (from the edit or delete action to index, usually).

You can also use the Redirector with an absolute URL, by using the gotoUrl() method:

$url 'http://www.akrabat.com';
$this->_helper->redirector->gotoUrl($url);

I tend to use this one much less frequently - so infrequently, that I can't think of a use-case off the top of my head :)

By default, Redirector sets a 302 status code, however you can also set a 301 if you want to:

$this->_helpers->redirector->setCode(301);

There are a few other options that can be set like setExit() and setUseAbsoluteUri(), but to be honest, I don't think I've ever used them!

I find that I use Redirector fairly frequently as its gotoRoute() uses the same parameters as url() which makes it easy to remember how to use it. Like url(), it also benefits from remembering which route was used to get you to the current page and reuses that when creating the next one which is handy.

Zend Framework's Flash Messenger action helper

23rd August 2010

I've talked about Zend Framework's action helpers before, but haven't covered any of the action helpers that are supplied with Zend Framework.

FlashMessenger is a helper that allows you to store messages between requests. The most common use I have for it is for a "saved" message after doing an edit of an item that then redirects back to a list.

This is how it's used:

Storing a message

Storing to the FlashMessenger is easy. This is my typical usage within an action controller:


$this->_helper->flashMessenger->addMessage('Task saved');
$this->_helper->redirector('index');

This code adds the message "Task saved" to the FlashMessenger and then redirects the user the index action, which in this case is a list of tasks. As should be obvious from the name of the method, you can add multiple messages and they will all be stored for retrieval after the next redirect.

The FlashMessenger will store the message that you've added for one hop, or number of requests. This means that the message will be available for retrieval on the next request, but unavailable on the request afterwards. This is very useful and it means that if someone refreshes the task list by hitting F5, then the "Task saved" message does not reappear.

Retrieving the stored messages

Retrieving the stored messages is similarly simple:


$this->view->messages $this->_helper->flashMessenger->getMessages();

This will create an array of messages in your view object which you can then loop over in your view script:

<?php if (count($this->messages)) : ?>
<ul id="messages">
<?php foreach ($this->messages as $message) : ?>
    <li><?php echo $this->escape($message); ?></li>
<?php endforeach; ?>
</div>
<?php endif; ?>

and that's all there is to the FlashMessenger.

Speaking at PHPNW 10

13th August 2010

The PHPNW conference is coming to Manchester again this year on the 9th October 2010 and I'm going to be speaking!

With a nod to the future, I'm going to be talking about Zend Framework 2.0. I'll be talking about why there will be a ZF2 and what's going to be coming up with the release.

PHPNW is a great conference and this year has expanded to three tracks! It's only £58 too if you book before 4th September. There's lot of ZF content too along with plenty of other great talks covering all aspects of PHP development.

If you are in the UK this October, make sure you come along!

New Zend_Auth tutorial

26th July 2010

After too many months of neglect, I have completely rewritten my Zend_Auth tutorial so that it is compatible with Zend Framework 1.10!

As an experiment, I have written it directly in HTML, rather than PDF as before and cover the login form along with the login controller code required to authenticate a user using a database table. For good measure, I've included logging out and a view helper to show how to access the logged in user's details.

The full source code is also available, if you don't want to type it in :)

I hope you find it useful.

Akrabat_Db_Schema_Manager: table prefix support

20th June 2010

I've updated Akrabat_Db_Schema_Manager so that it now supports table prefixes.

It uses the application.ini key of resources.db.table_prefix as I couldn't think of a better one :) and then uses that for the schema_version table's name and also makes it available in your change objects.

For example, if application.ini contains resources.db.table_prefix = "myapp", then the manager will create the table myapp_schema_version to store the current version of the schema. In your change classes, you can then do this:

001-Users.php:


 class Users extends Akrabat_Db_Schema_AbstractChange 
 {
     function up()
     {
         $tableName $this->_tablePrefix 'users';
         $sql "
             CREATE TABLE IF NOT EXISTS $tableName (
               id int(11) NOT NULL AUTO_INCREMENT,
               username varchar(50) NOT NULL,
               password varchar(75) NOT NULL,
               role varchar(200) NOT NULL DEFAULT 'user',
               PRIMARY KEY (id)
             ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
         $this->_db->query($sql);

         $data = array();
         $data['username'] = 'admin';
         $data['password'] = sha1('password');
         $data['role'] = 'admin';
         $this->_db->insert($tableName$data);
     }

     function down()
     {
         $tableName $this->_tablePrefix 'users';
         $sql"DROP TABLE IF EXISTS $tableName";
         $this->_db->query($sql);
     }

 }

which will create a table called myapp_users. Note that you are responsible for using the prefix property as the change classes cannot enforce what you do within the up() and down() methods. It also follows that you'll have to ensure that your models also use the correct prefix.

I have also made a change to the provider (Akrabat_Tool_DatabaseSchemaProvider) so that it loads the correct application.ini file based on the data in the project's profile. This shouldn't affect anyone using Akrabat_Db_Schema_Manager, except that we no longer define APPLICATION_ENV and APPLICATION_PATH for you.

Enjoy!

The Dutch PHP conference 2010

16th June 2010

This year I was invited to speak at DPC 2010 which was a great conference. I've published to Flickr, my complete set of photos from DPC 10.

Arriving on Wednesday, the day before the conference, I managed to get to meet up with my friend Juliette, along with a some of the other speakers for a barbeque which was a lot of fun. We ate, we drank (lots) and possibly this pose by Chris was the most surreal picture I took that evening!

I cannot even begin to think of a caption

On tutorial day, I gave a Zend Framework tutorial with Matthew Weier O'Phinney which seemed to go down quite well. We took a different approach this year to the previous ones that Matthew has given in that we talked about different application patterns and components that you can use in your ZF application; rather going through building an application from scratch. This had the benefit that we could talk about stuff that we wouldn't have got to normally. There were some other excellent tutorials that I was sorry to miss; I'm not quite sure how the attendees were able to make up their minds!

The conference was opened by Lorna and then Kevlin gave the opening keynote speaking about 97 things every programmer should know. This was an excellent keynote which fired us up for the day. In the morning, I gave my presentation on Zend_Form which I didn't feel came across quite as well as I could have done. I should probably revisit the content and pack some other bits in. This talk clearly showed the difficulties of aiming a presentation at the audience's level as I had some people there who had never used Zend_Form and others who knew it and were looking for more nitty-gritty details. Maybe I didn't set their expectations correctly at the start.

There were many other excellent presentations on the first day an I managed to catch Johannes' talk, 'Under PHP's hood' about what goes on within the PHP engine. An excellent talk with content that I highly recommend every PHP developer learns. I finished the day listening to Cal talk about Flex and whilst he hasn't convinced me to go that route, I know actually know a little about what it actually is!

In the evening, I had dinner with the other speakers and then we went to the conference social hosted by Ibuildings and github. This was very well attended and I had several good conversations with people.

Social

The second day of the conference started with a keynote by Chris Shifflet about Security patterns. I had already seen this talk and it was just as fascinating seeing it again. Definitely lots to think about. I gave my last talk of the conference immediately after the keynote and spoke on Deployment. I felt that this talk went well and that most of the audience got something out of it.

In a break from technical content, I went to see Elizabeth's talk on technical writing. Whilst I consider myself competent, I learnt lots and managed to not embarrass myself too much during the interactive section when I was volunteered (thanks Chris!) to go up and help Elizabeth illustrate a point. I also managed to drop in on the uncon and see Juozas and Ben talk about Doctrine 2, which seems to be considerably better than D1. The conference ended with a panel of leading lights in the PHP world talking about PHP and where it's headed.

Closing keynote panel

After conference ended, I went with a number of other people to a pancake restaurant and had an excellent meal, followed by a drink (or two!) with friends in the hotel bar. I had joked earlier in the evening that the bar bill would end up being paid by whomever was left standing at closing time... mdgm and myself had that honour :)

Again, DPC 2010 was a great conference and I want to thank Lorna and the DPC crew again for inviting me.

Community Review Team for Zend Framework

9th June 2010

On the ZF mailing lists, there's been a discussion on creating a community team with a follow-up by Matthew.

I was going to write up a little about it as I'm one of the volunteers on the team. However, Pádraic beat me to it and I don't think I could have written it any better, so go and read his write-up instead!

The CR Team at the moment is:

  • Rob Allen (Akrabat)
  • Pádraic Brady (PadraicB)
  • Steven Brown
  • Shaun Farrell (farrelley)
  • Pieter Kokx (kokx)
  • Dolf Schimmel (Freeaqingme)
  • Ben Scholzen (DASPRiD)

(alphabetical order has always suited me!)

We all accept email and can be found on irc in #zftalk.dev (freenode). Most are on Twitter too. Feel free to contact any of us about anything to do with contributing to Zend Framework and we'll find someone to help you!

MongoDB on OS X with the stock PHP installation

5th June 2010

MongoDB was mentioned a few times at tek and I said that I wanted to have a look at.

Travis' article, MongoDB: A first look, came out a few days ago and piqued my interest further. Then Matthew sent me some source code that requires it. The stage was set for getting MongoDB working on my Mac.

MongoDB

I use homebrew as a package manager for installing open source bits and bobs like couchdb, git, and hg. Installing MongoDB was simply a case of:

brew install mongodb

Once, installed there's a convenient LaunchAgent plist supplied so that mongodb starts with the computer:

cp /usr/local/Cellar/mongodb/1.4.3-x86_64/org.mongodb.mongod.plist ~/Library/LaunchAgents
launchctl load -w ~/Library/LaunchAgents/org.mongodb.mongod.plist

And at this point, MongoDB is installed on your Mac and Travis' article and the tutorial work!

The Mongo PHP extension

If you've been following along here for a while, then you'll know that I use the stock PHP that comes with Mac OS X. I've been very happy with it so far and installed Xdebug was easy enough using pecl, so I was hopeful that the mongo extension would be equally simple.

Turns out that it is!

pecl install mongo

Compiles the extension with no problems.

To add it to your PHP install, edit php.ini and add:

extension=mongo.so

A quick sudo apachectl restart and phpinfo() shows this:

MongoDB in phpinfo

All done! You can now get at MongoDB from your PHP scripts.

Tek.X recap

1st June 2010

TekX (pronounced Tek-Ten) has finished and we've all gone back to our respective daily lives. I had a blast and learnt a thing or two as well... I've also been a little busy, which is why this post is "late".

The week started on Saturday when I flew to Chicago from Manchester. Rather helpfully, tek was held at a hotel close enough to the airport, that the hotel had a free shuttle. As a tip for next year, you need to phone the hotel to come and collect you if you don't land at the terminal next to the train station.

On Sunday, Lorna, Derick and myself went to Chicago city centre; apparently, this is known as "downtown". We were intending to do a river boat trip, however that was all booked up, so we ended up grabbing lunch; having a look around Millennium Park and then doing a walking tour with the Chicago Architecture Foundation. This turned out to be an excellent tour. The lady was extremely knowledgeable and shared her knowledge freely. it was a very enjoyable afternoon and I feel that I know much more about Chicago's history now.

Chicago's skyline reflected in 'The Bean'

I ended up working much more than I expected over the week, however, I did manage to make nearly all the sessions I wanted to. Due to a scheduling conflict, I missed Kristina's tutorial on MongoDB as I was giving a Zend Framework tutorial at the same time! My tutorial seemed to be appreciated and I hope that those attending learnt something new. It was an introduction to Zend Framework, starting from first principles; in Amsterdam next week, at the Dutch PHP Conference, Matthew and I will be doing an all-day tutorial covering the next level of Zend Framework usage.

Josh Holmes opened the conference proper with his Simplicity keynote. I've had the privilege of seeing this at PHPUK earlier this year, however, a second listen was appreciated. Josh showed us his theatre background when the mic failed by continuing to talk and projecting his voice all the way to the back of the room. I gave my talk on Zend_Form next, which also seemed to help people learn a little more about the component. As there's probably more confusion over decorators than anything else, I concentrated on them, which may have made them clearer for those who saw it.

I don't want to provide a run down of all the talks as exploring the joind.in page will tell you more than I could here. I do want to highlight a few though. Lorna's talk on Subversion and DVCSs was the most objective and balanced discussion on an emotive topic. I had seen an earlier version at my local user group and Lorna really pulled out all the stops at Tek to give the best session I've seen her give. Having missed her tutorial, I made sure that I went to Kristina's talk on MongoDB. I've heard some rumblings in the Twitter stream about Mongo, but didn't actually know anything about it before her talk. It is always a pleasure to listen to an expert who is passionate about her subject. Talking about passionate, Elizabeth's talk on cross-platform PHP was a study in how you don't need many slides if (a) you are angry and (b) slightly hungover and so are prepared to rant! I thought I knew all the pitfalls of developing PHP sites for both nix and Windows, but Liz managed to point out a few more to think about.

Liz gets angry during her talk!

Tek is a very community oriented conference and it did feel that there was an open atmosphere where talking to each other was encouraged. This is known as the "hallway track" and I found it very beneficial, managing to get some useful conversations with people who know far more than I do. This definitely increased my knowledge and hopefully those who talked to me also gained. I also managed to get some time with Chris "phpdeveloper" Cornutt who helped me get the joind.in source code working on my computer so that I can help the project by fixing the bits that annoy me the most :)

Potbelly sandwiches

Finally, I'd like to thank Marco, Cal, Keith, Arbi and Beth for hosting an excellent conference and inviting me to speak at it. Hopefully, I'll be able to go next year too!