Tag Archives: Zend

A view of syntactic PHP features

This post explains how to add a new Syntactic feature for PHP but better, it shows how they actually works and how the tokenization of PHP is done.

Even if you never do this, it is still a good reading: http://nikic.github.com/2012/07/27/How-to-add-new-syntactic-features-to-PHP.html


Scalable, Flexible, Portable PHP in the Cloud – Webinar

Scalable, Flexible, Portable PHP in the Cloud Webinar from Zend

RightScale and Zend recently introduced a solution to provide a best practices path to launching and maintaining highly-available PHP applications in the cloud. Learn more about the RightScale and Zend Solution Pack: attend our webinar on August 17.

Join us on August 17 for a demo of this new cloud solution that
enables you to:


Provision a pre-configured, high availability PHP environment
in minutes
Autoscale your application based on system and application
load metrics
Receive system, server and application-level monitoring,
alerting and diagnostics
Abstract your application from underlying cloud infrastructure to
enable future portability
Topic: Introducing “PaaS in a Box”: Scalable, Flexible, Portable PHP in the Cloud
Date: Wednesday, August 17
Time: 9 AM PT / 12 PM ET / 5 PM BST / 6 PM CEST
Speakers: Uri Budnik – Director ISV Partner Program, RightScale
Claudio Gentile – Sales Engineer, RightScale
Kevin Schroeder – Zend Technology Evangelist, Zend



Free PHPUnit Training

Free is always better!!!!

Found this gold mine in the Zend Developer zone.

“It is a workshop that builds a small demo application the Test Driven Development way. The reason I open this workshop course is because I strongly believe everybody should understand and use PHPUnit in their projects”

More info at: http://devzone.zend.com/article/12765-Free-PHPUnit-Training

Direct link: http://blog.nickbelhomme.com/php/phpunit-training-course-for-free_282

ZendCon 2010 – Zend Takes Enterprise PHP to the Cloud

Fresh from the press:

Zend Technologies, the PHP Company, today announced a new cloud application platform to accelerate enterprise PHP adoption in the cloud. The Zend PHP Cloud Application Platform provides access to cloud application services and management while delivering elasticity and high availability. The Zend Cloud Application Platform sets the standard for PHP cloud application development and deployment, providing an enterprise-grade Web application infrastructure while maintaining the freedom to choose cloud infrastructures and services.

Zend PHP Cloud Application Platform Overview:

·         Native and portable cloud services – rapid development of cloud or native cloud applications using Zend Framework components

·         Cloud-ready development environmentIDE support for cloud application development and debugging

·         Enterprise PHP stack – high-performance, supported application stack including PHP, Zend Framework, necessary extensions and drivers

·         Deployment and management – PHP configuration management for easy scale up and error prevention

·         Monitoring and diagnostics – application monitoring and diagnostics across multiple server instances for identification and triage of application- and service-level issues

·         High Availability – cloud-ready PHP session management and graceful shutdown for fault tolerance and streamlined maintenance

More details at the original article: Zend takes enterprise PHP to the Cloud

Error Handling for different modules on the Zend Framework


Error Handling is a default form for Exception treatment on the Zend Framework. The Framework will register the Zend_Controller_Plugin_ErrorHandler and this plugin will by default listen to all controllers and it will do whatever you set to do on the ErrorController ErrorAction defined by you.

Give it a check on the framework documentation: Zend Controller Plugins

The trouble starts when you need to have a new way to handle exceptions differently for each module. Let’s say for instance that the default module is the main site and the secondary module is the shopping cart or a cell phone site.

Just to make the example more clear, imagine that for each module you want to have a different way to display a 404 page.

The documentation correctly shows how to set the plugin in order to use another module, but it don’t show you where. For setting up the plugin to accept another controller, action and view to another module you need to set those rules under the constructor of the module bootstrap or under the constructor of the main bootstrap.

Considering that the following is under the bootstrap for the shopping cart module you would have:

public function __construct() {

$front = Zend_Controller_Front::getInstance();
$front->registerPlugin(new Zend_Controller_Plugin_ErrorHandler(array(
‘module’     => ‘shoppingcart’,
‘controller’ => ‘static’,
‘action’     => ‘error’


For a reason which I could not understand until this moment, placing this plugin register in any other place will not work. Keep digging at it. Upates soon!!!

Have fun.

Zend Framework – Zend Currency

Today I got myself up with searching on Google and trying to understand the Zend Currency (a great way to easily format numbers in currencies format – PHP does have a function but it does not work under Windows) examples in the Zend Framework documentation. Whatever I did it was not working until I have bumped into a help manual from Zend that showed a better example.

Basically, the Zend Currency will totally bypass the parameters in the array and throw an error if the like the examples on the API documentation are set:

$currency = new Zend_Currency(
‘value’   => 100,
‘display’ => Zend_Currency::USE_SHORTNAME,
print $currency; // Could return ‘USD 100’
In order for this to work you need to first create the Zend_Currency object passing the locale and currency format (or if you don’t pass any parameter, it will just grab the format and locale from the system).
$currency = new Zend_Currency();
echo $currency->toCurrency(100); // could return USD 100
If you need to pass the locale or currency format this is how you can do:
$currency = new Zend_Currency(‘en_US’, ‘EUR’); // set locale to USA and the currency format to Euro
echo $currency->toCurrency(100);
If we do this same example following the API documentation we would:
$currency = new Zend_Currency(array(‘locale’ => ‘en_US’, ‘value’ => 100, ‘currency’ => ‘EUR’);
echo $currency; // doesn’t work unless you set the locale using the Zend_Registry and Zend_Locale
Anyway is worth to log this kind of troubleshoot.
Have fun.

How to get Zend_Tool working under Windows 7

This is a great post and resource form Calevans Blog. It’s a small step by step on how to get the Zend Tool working under XAMP in a Windows 7 environment.


Have fun.

Instaling Zend Studion on Ubuntu 64

Julian just came with a detailed tutorial of how to install Zend Studion on the 64 edition of Ubuntu.

It has both solutions, installing the normal version and the 64 version of Zend Studio.

Check it out: http://www.smooka.com/blog/2009/11/02/installing-zend-studio-on-ubuntu-64-bit/

PHP Basic Series – POST, GET & REQUEST

One of the major goals of PHP is to allow a common website to be fully dynamic. For that can be used database requests, form posting, changing information when parameters change, etc.

No matter when working with AJAX/PHP/MYSQL or PHP/MYSQL or simply PHP/MAIL you will probably be using the pre-defined variable arrays of $_POST, $_GET, $_FILES or $_REQUEST. Among these there is one more variable that you should have knowledge about, the $_SERVER variable that holds all the server environment information and is also an array.

[Note]: All these arrays are associative


The $_POST array will hold all information that have been passed by a HTTP POST method, or in a simple way, all information that have been passed by a post form and all this information will become a associative index on the array. Per example, if you have a input text box that is named “name” to access it via post you would use $_POST[‘name‘];

It’s always easier to understand the flow of information when you have more than one page, so let’s consider a 3 page application in wich:

  1. Page 1 will hold the post form
  2. Page 2 will process the post
  3. Page 3 will show a thank you message

Page 1: form.html (note that since we are gonna be using php script on the page, there is no need for the php extension even knowing that you can use it).

<form method=”post” action=”processForm.php”>
<input type=”text” name=”username” value=”” /><br />
<input type=”submit” value=”submit form” />

It’s a very simple page with a form and a textbox that will submit the information, once posted, to the processForm.php file, that, will process the post request. Note that on the form method the post is defined, but you could use as well the get method. The only thing about using the get method is that it will submit all the values on the browser url as part of a querystring and it would be necessary to use the $_GET variable to request the values.

Page 2: processForm.php – The process posted form page

if (!empty($_POST)) // checking if a post has been completed

if (strlen($_POST[‘username’]) > 0)
// has something, let’s force to go to the thanks page
header(‘location: thanksPage.php‘);


[Note]: Since is a full PHP page you don’t need the closing tag (in red).

Page 3: thanksPage.php – The thank you for posting page

At the last page of the example we will show a thank you page to the user for posting he’s username information.

<p> Thanks for posting the form </p>

The last page is quite simple and it’s a simple thanks message as part of the last process to be done to complete the post method.

Looking into a simple work flow we would have:

[page 1: form] [enter information] [submit]
{ form is posted to the processPost.php page } :: [page 2: processing] [check if the form has been submited] [check if the username was given]
{ page is redirected to the thanksPage.php } :: [page 3: user message] [show message] [end]

As you have probably noticed by now if the username is not given it will only show a blank page, we would not have a error message being show or even a return to the previous page. Another thing is that even that the username is given, there is no validation what so ever over the submited post.

This is where the $_GET comes to be extremely useful. Get should be used to communicate parameters between pages, but only communicating those parameters that does not contain sensitive information such as passwords or credit card numbers. As example, think in a AJAX call to a php script where the goal is to filter the search based on a given parameter. This is actually done by using $_GET on the php side and passing the filters by a querystring.

Since we don’t really need a form posting to use the get, let’s first demonstrate how to send parameters between pages using the $_GET array. To better understand the process let’s create a 2 page set where the first a user will click a link that will set a parameter on the second page.

Page 1: Links with parameters

<a href=”processGet.php?showmsg=1&msg=it%20worked “>click me to set parameters</a>

Note 3 elements on that link:

  1. The elements in bold: The ? starts the querystring and whatever comes after it is a parameter that will be passed to the $_GET array. The second element in bold, &, is used to identify any other parameter that will be used on the querystring. After the question mark, all other parameters must use the & to be identified.
  2. The elements in green are the parameters name. The same name that will be used as index on the $_GET array.
  3. The elemenst in blue are the parameters value.

To get those parameters and it’s values, you need a PHP page to parse the $_GET array, so let’s check the page 2.

Page 2: processGet.php – parsing the $_GET array to retrieve the querystring parameters.

$showMsg = $_GET[‘showmsg’];
$msg        = $_GET[‘msg’];
if ($showMsg) { echo $msg; }
// the equivalent to this is echo ($showMsg) ? $msg : ”;

The second page will check if the first parameter, showmsg, is set to 1 (or true) and if so it will display the msg “it works” on the page for the user.

[Note]: Since this is a php page with html tags in it, you need to close all open php tags (in red).

$_POST and $_GET become really helpful when working together. You would use the post to safely communicate data and the get to inform when something went wrong or simply to exchange information between pages.

Let’s get the example given to $_POST and add some $_GET parameters to communicate the information between page 1 and 2.

Page 1: form.php (note that the extension has changed)

$hasError = $_GET[‘error’];
$errorType = $_GET[‘type’];
<?php if (!empty($hasError)) { ?>
<p><? if (!empty($errorType) && $errorType == 1) { echo ‘Please enter your username.’; } ?><br /></p>
// if you had more than one type you could parse all errors here
<?php } ?>
<form method=”post” action=”processForm.php”>
<input type=”text” name=”username” value=”” /><br />
<input type=”submit” name=”submit” value=”submit” />

Page 1 (form.php) contains the form that will submit the username information to the processing php page (processForm.php) and also contains a validation using parameters got from the $_GET array. These parameters will be sent by the second page, proccessForm.php, when an error on the submission is detected.

Page 2: processForm.php

if ($_POST) {
$username = $_POST[‘username’];
if (empty($username)) {
header (‘location: form.php?error=1&errortype=1’); // this will display an error message asking the user to enter his username information on the 1st page.
else {
header (‘location: thanksPage.php’); // the information was correctly given, so redirect to the thanks page.
else {
header(‘location: form.php?error=1&errortype=2’); // this could show a message warning the user that a post submission is needed to process

With the help of the $_GET array and querystring now we have much more control over the form submission with a very basic validation and at the same time making the form much more dynamic.

I have mentioned above about the $_SERVER, $_REQUEST and $_FILES and where does they come in all of this? Well the $_REQUEST is the same as the $_POST, $_GET and $_COOKIES altogether in one array. In a coding point of view is good to be using all separate since you know what is being sent and where it came from, but using the $_REQUEST is up to each developer.

The $_FILES array is used when you are posting a file through a form (file upload – remember to set the correct enctype on the form). The file will not be available on the $_POST array making the only way to access it through the $_FILES array. Within this array you can find information where it’s currently stored (the tmp file on the server), it’s real name, type, etc.

To wrap up let’s take a look on the $_SERVER array. The server array contains all the information related to the server environment, from the PHP_SELF – the script executing the php coding, to the SERVER_NAME. Check it out on the php manual page for more info or simply do a var_dump($_SERVER) to learn everything about your development server.

On the next post we will gather everything that we have learned here and place it in a small one page application (yeah multi-page is not really necessary, but make it simpler to explain) where we are going to request a username / password from a user to login.

Have fun.

New Page – Zend Certification Series

Searching a blog somethings is a bit annoying, so to make everyone life easier I have created a new page with the links for all posts about the Zend Certification Exam (currently PHP5 and in the future ZF).

Since is a page you can easily access it by the top menu or on the right menu

For now, a fast link: Zend Certification Series

%d bloggers like this: