Archive for the ‘The Book’ Category

New Zend Framework in Action MEAP

A new Zend Framework in Action MEAP PDF has just been released. This version has the final manuscript before we head into production and fix the bugs in it, typeset it and turn it into printed pages.

The changes for this version are:

  • Chapter 16, Creating PDFs, has been significantly reworked to include a running example.
  • New appendix A, A whistle stop tour of PHP syntax, mainly intended for programmers coming from another language wanting a quick overview of PHP syntax.
  • Tidy up of all chapters to fix styles and typos.

Posted by Rob on 21st June 2008 under The Book | 11 Comments »

New MEAP PDF released

A new version of the Early Access PDF for Zend Framework in Action has been released. This is the first one with every chapter in it.

The biggest changes are:

  • Chapters 2 through 7 have been edited
  • New chapter 8 (forms)
  • New chapter 16 (PDFs)
  • Far more source code released

Let us know your thoughts on it over on the MEAP forum.

Posted by Rob on 5th May 2008 under The Book | 1 Comment »

Review of Zend Framework in Action

Robert Bolton has posted a book review of Zend Framework in Action:

At times I felt like there may be too much ancillary topics covered, however, after finishing the book, I felt overall it was good that topics such as testing, deployment, and version control were covered. While there isn’t enough information to provide in depth coverage, it exposures the reader to these topics and provides enough information to get started, rather than just briefly mentioning it. And the coverage of the different components with the Zend Framework is comprehensive and understandable. If you are looking at working with the Zend Framework, I would definitely recommend this book.

He finds both good and weak points in the book and we will, of course, see what we can do to address the issues raised.

Posted by Rob on 11th April 2008 under Around the web & Reviews & The Book | 2 Comments »

New MEAP PDF Released

A new MEAP PDF has been released for those who have pre-ordered the book.

The big changes are:

  • Chapter 1 has been edited
  • Chapter 3 has been replaced with two new chapters: 3 and 4 now cover building the initial example website. Chapter 3 covers the setup, controllers, actionstack and database with Chapter 4 concentrating on Zend_View, Zend_Layout and the view helpers.
  • Chapter 13 on mashups with public web services is available.
  • Chapter 14 on caching is available.

Note that this MEAP renumbers all chapters due to the new chapter 3.

As always, let us know your thoughts on it over on the MEAP forum.

Posted by Rob on 18th March 2008 under The Book | 3 Comments »

Zend Framework in Action author forum

Since the only way to know about this is a single link on the right hand side of the main book page I thought I’d point out that the book has its own forum which is intended for the discussion of the book; mistakes we’ve made, things that aren’t clear, things you like, etc.

We are interested in all feedback and do make changes or additions according to your comments, although a side effect of Rob’s working on the popular, day-to-day topics that make up the first half of the book, has been that he faces the bulk of the questions (including from me!) so I’m a little nervous that bringing more attention to the forum is going to increase his workload. So, erh, sorry in advance if that happens Rob! Hopefully the next early access release should begin to balance that out a bit.

Posted by Nick on 8th March 2008 under The Book | No Comments »

Zend_View article at KillerPHP

The guys over at KillerPHP have posted a new article called Zend Framework Components Part 2: Zend_View.

As you can guess, it’s about Zend_View and goes how to create a Front Controller plugin that will automatically add a header and footer template to all your pages.

This is really useful if you are using Zend Framework 1.0.x, but don’t forget that Zend_Layout is coming for 1.5.

Posted by Rob on 15th January 2008 under The Book | No Comments »

Playing with AjaxContext

I had a play with the AjaxContext code that Matthew posted to the laboratory and it's quite nice.

This is how I set it up.

Firstly I grabbed the files from the laboratory subversion repository and placed them in my lib/ directory. I then took updated my path using set_include_path() ensuring that the new folder was first in the list.

Having set up the environment, I then loaded the action helper in my bootstrap:

PHP:
  1. $ajaxContext = new Zend_Controller_Action_Helper_AjaxContext();
  2. Zend_Controller_Action_HelperBroker::addHelper($ajaxContext);


Which is nice and easy!

We are now able to make an action ajaxable. I pulled out the feedback action in the review controller within the Places example application. This action is already "ajaxed" and so the view scripts create an XmlHttpRequest to the action and know how to respond when Json is returned. Ideal for testing the context helper.

In the ReviewController, you need to add a new public member variable called $ajaxable:

PHP:
  1. class ReviewController extends Zend_Controller_Action
  2. {
  3.     public $ajaxable = array('feedback'=>array('json'));
  4.    
  5.     // continues


The array contains a list of actions within this controller than may receive Ajax requests and a list of acceptable formats. In our case, we only support json, but you could equally support xml, html csv or plain text depending on the use of the action.

We then need to initialise the context in preDispatch():

PHP:
  1. public function preDispatch()
  2. {
  3.     $this->_request->setParam('format', 'json');
  4.     $this->_helper->ajaxContext()->initContext();
  5. }


It is intended that you can pass through which context you want using a request variable called 'format'. Unfortunately, you can't not have it in the request at the moment. This bug will be fixed :)

initContext() is actually quite a simple function. It does lots of checking to ensure that the context needs to be changed and then it changed the suffix for the view scripts to {format}.phtml, sets a content type header in the response and finally disables Zend_Layout's layout system (if it's in use).

In this case, the view script that is now rendered is called feedback.json.phtml which contains the following:

PHP:
  1. <?php
  2. echo Zend_Json::encode(get_object_vars($this));


This simply encodes all the variables that have been assigned to the view into Json format.

The processing of the request continues as normal and a little later, at the end of the dispatch cycle, the response is echoed back the browser with a nicely formatted Json object as intended.

Posted by Rob on 7th January 2008 under The Book | 6 Comments »

Whitepaper

A few weeks ago, we were asked to write a white paper on what the Zend Framework is for the Marketing people at Manning. Obviously, being a programmer, I reused and re-factored what I had already written for Chapter 1 of the book.

It's interesting taking an excerpt out of a larger body of work and trying to make it stand on its own. I ended up re-wording more than I expected and also re-ordering bits as they didn't make sense order that they are in Chapter 1.

I got some feedback on it a couple of days ago and apparently it looks useful which is good. It's going to be formatted up and presumably it'll be published on the Manning website. if it is, no doubt I'll link to it from the Resources page here.

Of course, now I need to go and rework Chapter 1 with the improvements that I've made!

Posted by Rob on 4th January 2008 under The Book | 3 Comments »

AjaxContext Action Helper Proposal

Matthew is really burning the midnight oil at the moment and has produced another proposal. This time, it is an action helper to integrate Ajax calls more easily into a ZF MVC application. I've shameless lifted the rest of the information in this post from the proposal.

Zend_Controller_Action_Helper_AjaxContext will detect a XmlHttpRequest and do the following:

  • Disables layouts (if enabled)
  • Determines if the current action should respond via AJAX
  • If the action is "ajaxable", it then determines the response format and:
    • sets the appropriate HTTP response header
    • changes the view script suffix to reflect the format

All that you would have to do is mark your action as "ajaxable" (what a word!) by creating a public member variable called $ajaxable in your Controller and calling the helper's initContext() function in your preDispatch() like this:

class CountriesController extends Zend_Controller_Action 
{ 
   /**
     * Actions that allow an AJAX context
     */ 
    public $ajaxable = array('autocomplete'); 

    public function preDispatch() 
    { 
        $this->_helper->ajaxContext()->initContext(); 
    }

    // rest of class continues...
}

In this case you would be setting up the autocomplete action of the countries controller to respond using JSON or XML if called via the browser's XMLHttpRequest object. Hypothetically, in this case, it may be an autocomplete listing attached to a form element for selecting your country in a comment form.

Certainly, this action helper will replace some of the code I currently have in a Front Controller plugin that's designed to handle this problem. My code is considerably less flexible mind you, so I'd even gain some power!

Go and read the proposal on the Wiki and add comments. Your comments will make the component better!

Posted by Rob on 3rd January 2008 under The Book | No Comments »

Two-Thirds Review is over

The two-thirds review has been done. This is when the manuscript is sent out to 7 reviewers who then tell us what we are doing wrong.

Fortunately, nothing major stood out, with the main issues being related to style of writing.

Posted by Rob on 16th December 2007 under The Book | No Comments »