A 64-bit development environment

The 64-bit version of Google Chrome was released yesterday. This is a step forward to have a 64-bit compatible development environment.

Before, it was not easy: the Java runtime, Eclipse and Chrome are all linked together. If one did not support 64-bit, it did not work. And installing 64-bit Java next to 32-bit just isn’t a proper solution.

But now there is a 64-bit version for almost all software I need for PHP development:

The 64-bit environment really makes a difference when using Eclipse. It is much faster. This is the same for Chrome: a huge improvement.

Using Cisco NAC API with PHP (cURL)

The Cisco NAC Guest Server provides an API for other applications to interrogate the NAC.
I didn’t use cURL before, but now it was the best option to use since I didn’t have Zend Framework or anything else.

Off course, the first attempts always returned “false”. It never works from the first time. After some searching, this piece of code did it:

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_USERAGENT, "Dummy text");
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  $result = curl_exec($ch);
  $error = curl_error($ch);
  if ($result) {
      return $result;
  } else {
      return $error;

I needed to parse the response, so the transfer must be returned as a string; therefor CURLOPT_RETURNTRANSFER is set to “true”.

The NAC server expected a User Agent, so I needed to add that option: CURLOPT_USERAGENT. It doesn’t matter what value it has, but it needs something.

Because I didn’t needed to configure any certificates clientside (in cURL) I could set CURLOPT_SSL_VERIFYPEER is set to false.

The last problem I had, was that everytime something didn’t work, I only got “false” as answer. To get an error message from cURL it is necessary to read it out from the connection with “curl_error()”. This function returns the latest error message.

To simplify things, my function returns the result as a string, or the error message.

PHP 5.1 cannot connect to MS SQL Server 2008

A few days ago I had to set up a new environment for an old PHP application. The webserver runs on PHP 5.1.1, and could not be upgraded.
One of the databases is a MS SQL Server 2008. PHP has extensions for all kinds of databases, so I enabled php_mssql.dll in php.ini. When I tested the connection, I got a fatal error: Cannot connect to database…

Well, after a few hours of searching, I found this blog:

It describes perfectly my problem, and the solution. I downloaded MS SQL Server 2008, copied the file “ntwdblib.dll”, and replaced the two existing files in WAMP with the file I downloaded. After a restart of Apache, the MS SQL database was found.

It seems that PHP 5.1.1 (released november 2005) does not support more recent versions of MS SQL Server, but luckily there is a solution!

Thanks to all the bloggers out there, who make problem-solving a lot easier!

Zend_Db_Select: Select query cannot join with another table

When I executed a query created with Zend_Db_Select in a Zend_Db_Table, I got the following error message:

Select query cannot join with another table

What is happening here? A very simple select statement with a join is not allowed in Zend_Db_Select?
To solve this mysterious matter, I decided to Google the error message, off course. Luckily, one of the first results I got was the Zend Framework manual, a page on Zend_Db_Table. Luckily? Not really, because the documentation only mentions “You can allow JOIN clauses on a select to allow multi-table lookups”. That’s great, but… HOW?

But as always, the documentation comes to the rescue! On the Zend_Db_Select page a comment points in the right direction. There exists an undocumented function “setIntegrityCheck(false)“. And if you see the code of Zend_Db_Table_Select, in the assemble() function, it becomes even more clear: there is indeed a parameter “$_intgrityCheck” that can ensure that selected columns are only from the primary table.

So I pass this function in my Zend_Db_Select statement, and now it is possible to do joins!

View helpers and variables not available in layout

I got a really strange problem while implementing a menu with Zend_Navigation. I added this piece of code in the Bootstrap.php:

    protected function _initNavigation()
        $layout = $this->getResource('layout');
        $view = $layout->getView();
        $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/navigation.ini');
        $navigation = new Zend_Navigation($config);

This is fine for creating a menu or breadcrumbs, but there is one big problem: after this code is in use, all custom variables and the View Helper Include path are not available any more in the layout phtml file.

For example “echo $this->name” just echoes null. Or the custom view helper “$this->myHelper()” cannot be found because the View Helper include path only contains the path to Zend View Helpers.

And writing the same code in the phtml file of a simple action does work!

So what is the relation between the code above and the problems mentioned?

It all starts at the first line of the function “_initNavigation()”: there is a bootstrap function for the layout. Unfortunately it is necessary to add another line to not have the problems above. It is needed to also bootstrap the view! So the code becomes:

    protected function _initNavigation()
        $layout = $this->getResource('layout');
        $view = $layout->getView();
        $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/navigation.ini');
        $navigation = new Zend_Navigation($config);

Now the layout AND the view are bootstrapped, and the custom view helpers and variables can again be used in the layout phtml file.

I found this interesting issue in the ZF Jira: ZF-9537. It has already been reported, but it is not an issue (see status). So this is supposed to be normal behaviour? Does anyone has a good explanation for this?

Zend Navigation: Breadcrumbs minimum depth

Creating breadcrumbs with Zend Framework is really easy:

  1. Create a menu structure (ini file, php array, …)
  2. add a small peace of code in the view file: “echo $this->navigation()->breadcrumbs()”
  3. open your page and you see… nothing

This is what happened to me on the home page of my most recent project.  All though the ZF manual indicates you just have to echo the breadcrumbs, nothing appeared.

The problem was this: my menu started at level zero, and ZF sets the minimum level that will be displayed to one. Luckily there is the documentation, but it is really annoying that the method “setMinDepth()” is not in the API, so it took me much longer to find out this method existed.

Url view helper

When creating a link in a view file to another page of your application, Zend Framework provides a view helper that is very handy: Zend_View_Helper_Url.

echo $this->url(array(
    'module' => 'abc',
    'controller' => 'def',
    'action' => 'ghi',
    'param1' => '1',
    'param2' => '2'
); // output: "/abc/def/ghi/param1/1/param2/2"

If you don’t provide the module, controller or action, the current module, controller or action will be used as default values.

I think this is a very easy way to create links inside an application, without retyping every time your controllers or actions.

PHP Benelux Conference 2011, Antwerp

Thanks to Ausy/Dataflow I will be present on Belgium’s most important PHP event of the year.

The 2010 event was great, and I was very happy I could be there. The schedule for this year looks very interesting too: tutorial on quality assurance and unit testing, RESTful web services, Doctrine, and ZF2.0. Those are already some of the talks I will attend.

All information can be found at conference.phpbenelux.eu

Already many thanks to the organizing crew! Hope to see you there!