Simple Glance At How To Setup Zend_Tool In Your PHP Zend Framework Application

This article is about my remarks and comments on the screencast of Jon Lebensold which talks on How To Setup Zend_Tool In Your PHP Zend Framework Application. I also list the quick steps to allow you to achieve this without viewing the video.

I was just trying to integrate Zend_Tool in my Zend Apps after watching a zencast by Jon Lebensold. The video was nicely executed by the famous Zend-Podcaster. The aim behind was to show how to integrate Zend_Tool into your Zend applications and how you can write your own extensions to Zend_Tool. I recommend you watch the screencast.

Else, if you don’t have the time right now and you want to do a quick-play with ‘Integrating Zend_Tool Into Your Application’, here’s some quick steps:

Assumptions:

  • Your are familiar with Zend MVC Framework
  • You have Zend Framework version >= 1.8
  • You are using NetBeans IDE
  • You are on a Linux distro or Mac and  you are familiar with a unix-based terminal  (else Windows users will just use zf.bat)

The steps are:

1) Download the source example code provided by Jon himself – I will refer to this code for the quick step below.

2) In your root folder, on your server where your whole zend application resides, example htdocs, make a folder named as bin

3) Inside bin, paste the following three files: zf.bat, zf.sh, zf.php
You can find those files inside the bin folder of the original ZF source package you downloaded at Zend’s website.

4) Inside your library folder, create a new folder ZC (i.e we are creating a new namespace or vendor space for our ZF project)

5) Now, ZC need the presence of two php class files to act as a manifest (Manifest.php) and a provider (VisitorProvider.php), respectively. (assuming you have already downloaded the sample code mentioned above, I let you observe what the code body is for each of those files)

6) Open the config file /application/configs/application.ini
A new entry is added:

autoloaderNamespaces[] = “ZC”

5) On your Terminal run the following 2 commands:

$ ./zf.sh create config
$ ./zf.sh enable config.manifest ZC_Tool_Manifest

6) Now test and verify that the Zend_Tool has actually integrated your new namespace

$ ./zf.sh

You should see among the list:

Visitor
zf hello visitor

Verify the command:

$ ./zf.sh hello visitor
Hello!

The result should be Hello!
Voila! That’s it! Simple? Well, thanks and credits go to Jon Lebensold for his excellent screencast explanations.

ZF Excetion – An Error Has Occurred. An action and provider is required

$ ls /[path]/htdocs/myzendapp/bin/
$ ./zf.sh

If you execute zf.sh or zf.bat, you will notice an error message as follows:
An Error Has Occurred. An action and provider is required

What this means?

First you need to understand those two terminologies as applied to the Zend_Tool. An action is something that you want to perform on your zend application, while a provider takes on the role of the controller and basically provides some functionality.

So, as you have guessed by now, the exection of the zf also expects some parameters. You would probably have seen a list of possible directives the Zend Tool provides on your screen.

For instance, to enable layout for your application, you would type:
$ ./zf.sh enable layout

Some Zend Terminologies As Applied To Zend / Zend_Tool

Jon also elaborated on some definition about certain terms often used with Zend_Tool / Zend, which I think is quite important to know. If I retained well, here some worthwhile terms:

  • Controller – what dictates a collection of different actions that you will perform on your application
  • Action – an individual method call that usually wraps a view
  • Registry – is used to store information that will eventually get rendered or like a local persistence during the running of any kind of Zend Tool task
  • Provider – will have the actual code we are trying to write
  • Manisfest – describes where to find that code

What Is Zend_Tool

Jon Lebensold describes Zend_Tool as a new kind of component which acts as an alternate interface for your Zend framework application; the idea being that you can generate your views, models, controllers, etc through a command line script that will essentially scaffold your application.

Ralph Schindler (a Zender) coined Zend_Tool as “a framework within a framework” in his Zend_Tool article at Zend Developer Zone.

Now, how would I define Zend_Tool?

I would say it is a tool which is aware of your project’s eco-system and which will help you to quickly generate the minimal skeleton and required resources essential for your project.

To put another way, it is like installing a new linux distro (mandriva or ubuntu) with some pre-configured development tools. Now if you want a specific software to run on your pc, you need to use, extend and build upon those tools to make it.

Zend Autoloading The New Namespace

UPDATED News: Jon has just clarified this thing with me, it’s more like the issue is with how to autoload new namespaces using the application.ini file instead of via classes. [Jon I apologize 😉 ]

One thing which Jon was not able to properly do, is to autoload a new instance of ZC_Tool_VisitorProvider. He made required_once call to include the ZC/Tool/VisitorProvider.php class file.
Here’s a glance at this file:
[lang=’php’]
/**
* Description of Manifest
* @author jon
*/

require_once ‘ZC/Tool/VisitorProvider.php’; //include file (instead of autoloading it?)

class ZC_Tool_Manifest
implements Zend_Tool_Framework_Manifest_Interface,
Zend_Tool_Framework_Manifest_ProviderManifestable,
Zend_Tool_Framework_Manifest_MetadataManifestable
{
public function getProviders()
{
return array(
new ZC_Tool_VisitorProvider() // new instance for
);
}
//…………..
}
[/lang]

A solution to this issue, is that you can register your new namespace inside your bootstrap class or any initialisation class.
Example: $autoloader->registerNamespace(‘ZC_’);

Here are two articles you might make some reference about zend namespace autoloading for now:

  • The Autoloader From Zend Programmer’s Reference Guide
  • Autoloading Zend Framework by Lysender



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.