Zend_Barcode – part 1 : using

Zend Framework 1.10 will integrate Zend_Barcode initially called Zend_Image_Barcode in the proposals.

The main difference between this first proposition and Zend_Barcode, it’s the separation between Objects and Renderers. This allowed to write an image generator (Zend_Barcode_Renderer_Image) and a PDF generator (Zend_Barcode_Renderer_Pdf).

This component internally uses a new version of Zend_Validate_Barcode specially rewritten for 1.10 by Thomas (http://www.thomasweidner.com/flatpress/2009/12/17/validating-barcodes/).

The official documentation will of course integrate the examples showing how to use the component but here is some use cases.

1. The image generator file ‘barcode.php’

You can put at the root of your Web server:

require_once 'Zend/Barcode.php';

2. A call in your view and… a first error

<img src="barcode.php?barcodeType=code39" />

This will of course give you an image of error:

Because no text is provided.

3. Your first barcode

You obtain it by simply adding the ‘text’ parameter:

<img src="barcode.php?barcodeType=code39&text=ZEND-FRAMEWORK" />

You have your first barcode in 5 lines of code:

4. A better font

If you use the image renderer (based on GD extension) and if you don’t specify a TTF font, the built-in fonts will be used. You can set your own font in the options of the barcode or by global definition:

require_once 'Zend/Barcode.php';
Zend_Barcode::render($_GET['barcodeType'], 'image', $_GET, $_GET);

You will obtain:

New website design and online documentation

Updated on 2011-12-24 to include 2.0 release.
Updated on 2010-12-30 to include 1.11 release.

I propose now on my website the online documentation for 1.6, 1.7, 1.8, 1.9, 1.10, 1.11 and 2.0:

Language 1.6 1.7 1.8 1.9 1.10 1.11 2.0
Deutsch See See See See See See
English See See See See See See See
French See See See See See See
Japanese See See See See See See
Portuguese See See
Spanish See See

I choose the main languages that are up-to-date.

It includes: syntax highlighting, extra documentation and a search engine (for each release).

All CHM versions have been reviewed to integrate these functionalities.

Adding extensions to Zend Server

For my translator tool for Zend Framework, I needed the pspell extension to add a spell checker to the tool and I also wanted to test the PHP SVN extension. Unfortunately, pspell and svn are not included by default in Zend Server. There are 2 ways to add it to Zend Server: using Zend Server sources or using PECL. I followed the below instructions to install them on my Ubuntu 8.10.

Installing PSPELL via Zend Server sources

First of all, as suggested by Jess comment (see below), you have to check the availability of differents packages to compile a PHP extension:

autoconf -V | grep '^autoconf'
#autoconf (GNU Autoconf) 2.61
automake --version | grep '^automake'
#automake (GNU automake) 1.10.1
gcc --version | grep '^gcc'
#gcc (Ubuntu 4.3.2-1ubuntu12) 4.3.2

Second: Aspell and languages that you want to check:

apt-get install aspell libaspell-dev aspell-en aspell-fr ...

Third: pspell library:

apt-get install libpspell-dev

Fourth: retrieve Zend Server sources (in my case PE Edition but you can do the same with CE Edition by replacing ‘pe’ with ‘ce’):

apt-get install php-source-zend-pe

Fifth: configure and compile extension (I use here the default installation directory ‘/usr/local/zend’, exchange the occurrences with your installation dir)]:

cd /usr/local/zend/share/php-source/php-5.2.9/ext/pspell
./configure --with-pspell --with-php-config=/usr/local/zend/bin/php-config
make install

Last: enable it in Zend Server configuration:

and check your phpinfo:

Installing SVN via PECL

Of course, you also need autoconf, automake and gcc like described above.

First: you need subversion libraries:

apt-get install subversion libsvn-dev

Second: you use PECL to install the extension, SVN is a beta extension for the moment, so you need to define explicitly the version you want. Or you can change PECL configuration:

/usr/local/zend/bin/pecl install svn-0.5.0
# or
/usr/local/zend/bin/pecl config-set preferred_state beta
/usr/local/zend/bin/pecl install svn
/usr/local/zend/bin/pecl config-set preferred_state stable

You will have 2 questions: prefix of Subversion installation and prefix of the APR installation used with Subversion. If you didn’t change them during their installation, you just have to keep autodetect.

Last: enable it in Zend Server configuration:

and check your phpinfo:

Special thanks to Remi Woler for the help and Jess Portnoy for the suggestions.