Archive for the Category Development

 
 

Zend Server, a first impression

Zend Server

I finally tried Zend Server Community Edition as a replacement of WampServer (or XAMPP) for local development.

While Zend Server proposes to be the perfect solution for any environment, I specifically tried it as a development stack on Windows machines. The use and usefulness of course completely differ in any other scenario.

First of all (and of great importance if you ask me): it is clean, simple and easy to use from A to Z. The installer provides the right options but not too many, the dashboard (control panel) is slick and provides quick access to settings you don’t often find in any other “server packages” and last but not least it performs much better due to the use of FastCGI on Windows.

2 less-frequently used features I missed though:

  • A way to set up VirtualHosts in the dashboard.
  • A WampServer-like way to switch between PHP (and in a lesser extend Apache) versions.

In total, the fine packaging almost got me convinced to replace WampServer.

Almost… because the choice for FastCGI on Windows also has one major disadvantage: you cannot use php_value settings inside your Apache/VirtualHost configuration. I especially like this since it avoids setting include_path, display_errors, upload_max_filesize and the like inside your scripts or .htaccess (which in some setups causes it to be parsed at every request).
Doing this in Zend Server on another platform isn’t a problem, since they use the PHP Apache module instead of CGI but that means you do not have similar environments and that is the complete opposite of what we want.

So it ended with a deinstallation. On the other hand: I can really see the benefit of this package for live/production environments. With it’s included optimization tools it takes a lot of configuration hassle away.

Google results right-click FireFox reset

When you use FireFox, you might notice that the Google search results show a different URL once you click on a link.

Google has been experimenting/implementing/… this for quite some time now but apparently not in all countries/browsers/users/… simultaneously?

It is caused by some JavaScript script that re-routes the link through Google in order for them to be able to track clicks. Although I can imagine some people make a fuss about this, personally I do not care as long as the results are good.

But this becomes annoying once you right-click a link to copy it (e.g. in an e-mail): I want to send the original URL and it sounds a bit strange to track other people clicking on my search result (for some good reason it probably makes sense to Google though).

You can easily avoid this (at least in FireFox) with a Greasemonkey script. Scripts have been available for some time, but I made a simple one with jQuery that does the trick for me.

Download or install jQuery Google click tracking removal script.

Use standards

Use standards

No, you guessed wrong. This will not be the nth post about W3C standards.

Well, maybe one paragraph: while I know the use of W3C standards is favourable, the usability of your project/application should be your number one priority. Not adherence to a standard which would render your application unusable for (a part of) your audience. Every once in a while people tend to forget this. Of course no one will argue that W3C standards actually are a blessing.

But, this post is mainly about 2 simple standards:

  • The ISO 639 standard for representing languages. Please use “en” or “fr” in your database, routing, scripts,… . It is unbelievable how many times people pick something like “FR” or “F”.
    Next time, consult the ISO 639-1 list.
  • The ISO 3166 standard for representing countries. Same case: please use “US”, “FR” or “BE” or use the ISO 3166-1 list.

Additionally, use the Unicode CLDR list when working with locale’s (e.g. nl_BE).

Standards in general provide a major productivity benefit: you do not have to lose time discussing, implementing, mapping,… other peoples personal preferences (whether or not their choice can be motivated).

This also applies to coding standards/guidelines. We have probably all had (or will have) discussions about them once in our life because there are no “official” ones as far as I know. Specifically about PHP: please (yes, I am on my knees right now) use one of the major ones that are already available: e.g. Zend Framework (my preference because it is or will become the industry standard), PEAR or … . Do not create your own flavour (I do not have to explain why this does not make sense).

A hot topic at your company, project or team? Have a look at Weble Subversion hosting: you can force a list of predefined guidelines/standards by a mouse click. This will prevent SVN users from committing their code if it does not comply and, in such a case, an overview of the deviations will be displayed.

Practical use of QR codes

Popular and widespread in Japan, QR codes (a variant of the well-known bar-codes) certainly provide many opportunities.

strictlyphp-qr-code

The QR code was invented by Denso Wave, Inc of Japan in 1994. They appear on many product packaging in addition to “normal” bar-codes for shipment tracking and other purposes. When scanned, these codes can return numbers and text (e.g. the URL to this blogpost in the example image). The camera on your mobile phone and dedicated scanning software do the rest of the magic.

While their ability to be a link between the “online” and “offline” world can provide many opportunities, it hasn’t really become the hype it could be outside of Japan. Practical implementations are rare. Most likely because of the lack of knowledge by the broad public. Although QR reader software is freely available and a July ’09 research by the University of Essex stated that 68% of UK phone owners can install such an application, most have not.

The biggest difference between the numerous free QR readers (for about any phone brand/model) may be the image quality needed to recognize a code. I’m happy with the  speed of NeoReader but there are also Kaywa Reader and QuickMark barcode reader (among others).

Besides WordPress plug-ins and support in the Google Charts API, there is a PHP library but support in the Zend Framework could stimulate its use even more (Zend_Gdata_Chart anyone)?

Some more implementations:

One useful tip is to shorten URLs through one of the many URL shortening services there are. This generates a smaller, less prominent QR code.

View specific JavaScript with Zend Framework

Because Zend Framework (and in this case also the MVC part) lets you choose how you structure your project, you may have doubted about where to place client-side JavaScript scripts.

icon_javascript

Personally, I place application-wide scripts in something like /media/js/application.js, but in many cases you have scripts that are only applicable to a certain view. Of course we want to avoid having a JavaScript file for each view somewhere in a general JS folder like /media/js.

Putting the JavaScript straight into the view also isn’t optimal since Zend_Layout can for instance put more HTML below it and client-side scripts should be right before the </body> tag.

I thought it would be nice to be able to have [viewname].js files inside the views/[controller] directories. E.g.:

PHP
1
2
3
4
5
6
7
/application
/controllers
BugController.php
/views
/bug
index.phtml
index.js

That makes development easier since your view-specific scripts are still as close to your view as possible, but separated in a .js file so your IDE/editor can parse them as JavaScript. In my case I thought it would also be nice if the .js file would be parsed like the view itself meaning that any variables assigned to the view can also be used in the JavaScript file.

The Zend_Controller_Action postDispatch() method provides a possibility to parse and include the client-side script into the inlineScript view helper where it belongs:

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public function postDispatch()
{
$request = $this-&gt;getRequest();
$controllerName =  $request-&gt;getControllerName();
$actionName =  $request-&gt;getActionName();
foreach ($this-&gt;view-&gt;getScriptPaths() as $path) {
$fileName = $controllerName . DIRECTORY_SEPARATOR
. $actionName . '.js';
if (file_exists($path . $fileName)) {
$view = clone $this-&gt;view;
$script = $view-&gt;render($fileName);
$this-&gt;view-&gt;inlineScript()-&gt;appendScript($script);
}
}
}

As you can see, the regular view script is cloned so that the same information is passed to the JavaScript file.

The only thing you now need to do is subclass Zend_Controller_Action, paste in the code above and use that new class in your controllers:

PHP
1
class MyController extends My_Controller_Action {}

Happy JavaScripting!

New PDT 2.1 available

Eclipse Galileo

With every new Zend Studio release (still beta) comes a new PDT version: this time based on Eclipse 3.5 Galileo.

While Eclipse Galileo brings some nice new features and bug-fixes (of which many are not important to PHP developers, but nonetheless) PDT actually impresses the most with PHP 5.3 support: syntax coloring and validation with namespaces awareness. More about this in the release notes.

The best news in my opinion: since the software/plugin/update manager of Eclipse underwent some major refactoring, it’s biggest disadvantage may as well disappear! The only sane way to upgrade from 3.4 (or older) to 3.5 is still: delete your old version and unpack the new one, but lets hope this was the last time…

And last but not least: Mylyn integration got even better (I really need to dedicate a post to this).

Be sure to try the new PDT version!

Ext on its way to world domination

Ext JS Core

While Ext JS turns 3 and already had a turbulent past, the development team has come up with a new project & licensing structure.

While it is still in beta, Ext JS seems to have been split up in an Ext JS Core library, which is a complete alternative to jQuery, Prototype, Dojo, Mootools,… and the upcoming full Ext JS library, which will probably include the features you know Ext best for: the slick user interface.

Together with the beta release of the core version, a bunch of popular widgets have been mimicked: Lightbox, Tabs, Image rotation and Context menu’s.

The Ext JS Core is MIT licensed, which basically means it is completely free. There was of course no other way to go because of the competition. But since the core version completely eliminates the use of any other JavaScript framework, it will pave the way even more for the full version. Together with the already huge Ext community (> 70000 registered members), world domination can’t be far away.

Although I have had a lot of fun with jQuery, I guess I no longer have a reason to use it. They seem to have done a fine job to offer a replacement (with a file size that almost matches)!

Why use a button tag instead of input?

When creating an application, developers and designers tend to invest to little time in a proper semantic (X)HTML structure.

The layout of your project probably won’t benefit from this and while SEO will, what makes it so important is that it simplifies your work  (or someone else’s in your team).

A good example is the use of <thead> and <tbody> tags inside tables. You can easily apply a different visual style to a table header without adding a class to the first row (thead tr {background-color: #ccc;}).

Another one is the use of <button type=”submit”> tags over <input type=”submit”>. When applying CSS styles, you will be able to style buttons separate of input fields. Can you see the advantage?

Project: get a quote for USB sticks

usbkey

For Cited (Dutch) I created a dynamic quote request form (Dutch) which allows potential customers to specify exactly what they are looking for (of course limited to the options that are available).

Through a secured back-end, the site-owner can specify which configuration options are available in which order for which products and categories. You may notice a lot of different configurations are possible!

Within the existing site, the MVC of Zend Framework was used to build only the form and back-end. It’s not ideal, but yet again proves the advantage of the ZF use-at-will structure: almost anything is possible.

So you now know where to get your next shipment of USB sticks/braces/cards!

Upgrade PDT 1.0.3 to 2.0

PHP Development Tools (PDT) for Eclipse makes me feel uncomfortable. I start to doubt myself because I cannot seem to find the intended way to upgrade to a new version.

Eclipse in general is such an well structured IDE: it has so many advanced features to increase your productivity (yes, I just saw a presentation by Mik Kersten about Mylyn). But for some reason, while using PDT 1.0.3, I cannot find a way to upgrade to a new version from within Eclipse. Using the update manager I mean. Isn’t that the most logical place to look?

Also, I wasn’t able to find one decent post about someone explaining how to do this. Because of that, I’m in doubt with myself: am I to stupid to see this or is it really not possible. I cannot imagine the latter is true so…

In the end I just downloaded the PDT 2.0 all-in-one package and unpacked it over my previous installation and everything seems to work fine. Maybe this is the only way to upgrade to a new version? No, never mind, this can’t be true.