Category Archives: Zend

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.

Redis PHP Introduction

I have just came across this article about installing and using Redis database-proxy-cache system with PHP (very similar to memcache). It’s a very detailed article and it also has directions for those who use the Zend Framework.

Anyway, it’s a great reading: Redis PHP Introduction

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.

IoC – Inversion of Container

Today, Mark Richman, has presented me with the IoC concept. Something that I haven’t heard about until now, but it does make a ton of sense.

Basically it says that instead of calling the framework and invoking it’s objects, you would make the framework aware of your objects. How Michael Mattson’s would say, this is the Hollywood Principle: “Do not call us, we call you”.

There are some good proposals of  developing the Injection Container for the Zend Framework, but so far, at this moment looks like there isn’t any really developed therefore you can find a good library to take a look at Symfony Components.

Check out this article from Ibuildings. I has a good perspective of how it could be developed with the Zend Framework.

How to Study for the Zend Framework Certification Test

Great post on how to study for the Zend Framework Certification.

Follow the link:

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 resources

Happy Friday everybody ….

2 New resources for you to check out:

  1. Javascript Bookmarklets
  2. Zend Framework and Firebug – Log PHP warning, errors and exceptions

Don’t forget also of the PHPArch Free Webcast today about Running PHP on Windows with Hank Jansen and Zack Owens.

Have fun .. .

Don’t use strtoupper with Japanese characters

It’s not like you can’t uppercase characters from Japanese, Chinese, Korean, etc languages, but certainly using strtoupper is not the proper method.

I have passed the last 48 hours trying to find an error that was dying one of my view scripts. No exception has been set or displayed and no error or warning what-so-ever was being displayed. Chasing a bug like this is one of the hardest things you can do.

After a lot of slashhamer debugging (echo mktime(); die;) and help from co-workers and friends I finally could find where the bug was.

The problem was that I was trying to display a Japanese encoded page and simply trying to strtoupper the title was failing and dying the whole script.

After this was found out, then the logical exit was using mb_strtoupper to uppercase it, but it also failed. This time it was fully my fault. Mb_strtoupper uses mb_internal_encoding to get (and set) the internal encoding to be used with that function. If you don’t specify the encoding it will simply get the default therefore failing on the function call creating the origin of my whole ghost bug.

The simple and complete solution for this was setting the encoding to UTF-8 while calling the mb_strtoupper function.

Point is, if you are using a multi-language system and is most likely to be under LATIM1, then whenever using the mb_* functions you must set them to UTF-8, otherwise you will be chasing a ghost bug (and it’s not fun).

Setting the mb_* functions is easy, one of the parameters is always the enconding, so, for example, for the mb_strtoupper function, the function call would be:

echo mb_strtoupper(‘大文字mcloide wordpressのドットドットコム’, ‘utf-8’);

Have fun …

%d bloggers like this: