Archive for the 'Web Development' Category

Do PHP Files Require Closing Tags?

Thursday, March 9th, 2006

I don't know about you - but I always learnt to open and close my PHP files properly:

<?php
// Included PHP File
// Code goes here
?>

And yet now I am learning for the very first time that the closing PHP tags are not necessary, and in fact in some cases is not recommended!

The first clue I received was when I downloaded the Zend Framework. I noticed that most of the files were missing the closing tags (?>). Then somebody raised the issue on the Zend Framework Mailing List and the penny dropped:

  • PHP files have apparently never required closing tags
  • Leaving out the closing tags helps prevent whitespace sneaking into the ouput and messing with functions like header(), session_register() functions etc.

Well, that is definitely a new thought for me - and not one I have ever read anywhere. It sounds like it will make it into the Zend Coding Conventions though, so take note ;)

Zend Framework Tutorial

Wednesday, March 8th, 2006

For those who want to get started on the Zend Framework, Chris Shiftlett has just written a 6 page tutorial for the php|architect website. It is a good introduction to how the framework fits togethor, and will demonstrate how to structure a web application/site using the MVC (Model-View-Controller) approach.

Chris Shiftlett is a PHP security consultant and he developed a lot of the security features (input filtering etc) in the framework - his tutorial is certainly worth a look

It's Finally Here: The Zend Framework for PHP

Saturday, March 4th, 2006

ZendAfter many weeks of waiting impatiently the Zend Framework has finally arrived - proving that it is not the "vapourware" it has been labelled by many.

The news came from Zend came just a few minutes ago, and includes the following announcements from Andi Gutmans:

We have finally updated the static PHP Collaboration Project page which now points to the individual projects which we have started:

The Zend Framework - We have released a preview release of the Zend Framework. I'd like to thank all the initial contributors who have been of tremendous help in getting this off the ground. There is a lot of work still to do, but after having already seen four applications build with the framework, it is clear that it already includes some very cool and useful modules.

The Eclipse PHP IDE framework - We have submitted a proposal to the Eclipse Foundation for a community based open-source PHP IDE framework. If all goes well in next week's creation review, we will be submitting the initial code drop shortly thereafter. In the spirit of Eclipse, we have already reached out to community members, including the PHP/Eclipse project, and have received great interest to join the effort.

The Zend Developer Zone - We have launched our new developer zone. The goal of this developer zone is to provide best practices with high-quality content from partners and the community. We already have many companies and invidiuals lined up to collaborate around this site who will share their knowledge for the benefit of the PHP community. The site will cover many aspects of best practices including Zend Framework use, interoperating with other technologies, and general PHP best practices around subjects such as security. The Zend Developer Zone is still under active development so expect further changes in the coming week.

Here is a run-down of the features/classes included in the initial Framework release:

Zend_Controller and Zend_View

These components provide the base for a simple MVC website and are already used on the Zend Framework site and several others. A front controller dispatches requests to page controllers. It is as minimalist as possible and it will become even simpler. The Zend_View component provides encapsulation for view logic. It can use templates written in PHP or can be combined with a third-party template engine.
more >>

Zend_Db

Database access is a very light layer on top of PDO. Solutions for existing systems not using PDO (such as mysqli or oci8) are presently under development. Included are adapters, a profiler, a tool to assist with building everyday SELECT statements, and simple objects for working with table row.
more >>

Zend_Feed

The links on the sidebars of Zend Framework home page are generated using Zend_Feed. This component provides a very simple way to consume RSS and Atom data from feeds. It also includes utilities for discovering feed links, importing feeds from different sources, and feeds can even be modified and saved back as valid XML.
more >>

Zend_HttpClient

This component provides a client for the HTTP protocol and does not require any PHP extensions. It drives the web services components. In time, Zend will develop support for extension-based backends such as cURL.
more >>

Zend_InputFilter

The input filtering component encourages the development of secure websites by providing the basic tools necessary for input filtering and validation.
more >>

Zend_Json

Easily convert PHP structures into JSON for use in AJAX-enabled applications.
more >>

Zend_Log

Log data to the console, flat files, or a database. Its no-frills, simple, procedural API reduces the hassle of logging to one line and is perfect for cron jobs and error logs.
more >>

Zend_Mail and Zend_Mime

Almost every internet application needs to send email. Zend_Mail, assisted by Zend_Mime, creates email messages and sends them. It supports attachements and does all the MIME dirty work.
more >>

Zend_Pdf

Portable Document Format (PDF) from Adobe is the de facto standard for cross-platform rich documents. Now, PHP applications can create PDF documents on the fly, without the need to call utilities from the shell, depend on PHP extensions, or pay licensing fees. Zend_PDF can even modify existing PDF documents. Create a sharp customer invoice in Adobe Photoshop, fill in the order from Zend_Pdf, and send it with Zend_Mail.
more >>

Zend_Search_Lucene

The Apache Lucene engine is a powerful, feature-rich Java search engine that is flexible about document storage and supports many complex query types. Zend_Search_Lucene is a port of this engine written entirely in PHP 5, allowing PHP-powered websites to leverage powerful search capabilities without the need for web services or Java. Zend_Search_Lucene's file format is fully binary with its Java counterpart.
more >>

Zend_Service: Amazon, Flickr, and Yahoo!

Web services are becoming increasingly important to the PHP developer as mashups and composite applications become the standard for next generation web applications. The Zend Framework provides wrappers for service APIs from three major providers to make the as simple to use as possible. There is working on more wrappers and engaging API vendors directly to make PHP the premier platform for consuming web services.
more >>

Zend_XmlRpc

PHP 5's SOAP extension dramatically lowered the bar for communicating with SOAP services from PHP. Zend_XmlRpc brings the same capabilities to XML-RPC, mimmicking the SOAP extension and making these services easier to use than ever from PHP 5.

________

It's time to verify if this was worth the wait - click here to download the Framework (7.8Mb)

AjaxTK: The Ajax Toolkit from Zimbra

Thursday, February 2nd, 2006

Zimbra LogoZimbra released the AjaxTK JavaScript development library last year. Running under the Mozilla Public License (MPL) developers can use this toolkit in their browser-based applications. The toolkit is actively used by Zimbra in developing the Zimbra Collaboration Suite, one of the most full-featured AJAX applications I have ever seen. Because of it's development in conjunction with a real-world application, and because of the number of widgets and JavaScript utilities included, AjaxTK may well be one of the most advanced JavaScript toolkits available at the moment.

There is a problem however - there is basically no documentation for using AjaxTK, other than an extremely technical overview of the framework in PDF format. There are currrently no online examples of the widgets being used (other than the demo of the Zimbra Collaboration Suite itself). And while you can download the toolkit from Zimbra, their examples are heavily tied into JSP which is a major problem for me because I have no intention of using JSP.

So - here is a small step toward helping the community to get started. Full credit goes to Xiris, Chouser, Zuser and especially Smies for their posts on the Zimbra AjaxTK Forums.

AjaxTK Tree ExampleZimbra AjaxTK Tree Example

open example here

This is a standard DHTML tree, but it also demonstrates Drag 'n' Drop and custom Tooltips. Try dragging a contact from the top branch onto the label of the second branch.

AjaxTK Grid ExampleZimbra AjaxTK Grid Example

open example here

This is an extremely full-featured example. It demonstrates tabs and a grid that has resizable columns, movable columns and column sorting. You can filter the listings on the left (which is fully client-side). And the grid listings are paginated, allowing you to open 3 pages of listings in the grid.

Download Examples and AjaxTK Library

The above examples and the full source code are available for download in a ZIP file (466kb). Once again, thanks to Smies for getting this working.

 

So … what do you think? How does this compare to other AJAX libraries in your opinion? To be fair to Zimbra, they have only fairly recently released this toolkit to the community and it is yet early days (like most AJAX projects). They have some very positive thoughts on what AJAX libraries should be able to acheive in the future, so hopefully this is an indication of where they will take AjaxTK…

If you liked this post you can digg it here.

Optimise your JavaScript and CSS

Thursday, February 2nd, 2006

The Zimbra team have posted an article with some very interesting tips on how to optimise your Javascript and CSS so that you can reduce the launch time of your website or application. There are detailed explanations of the methods used and a case scenario demonstrating a reduction in file-size of around 300-400%. You may pick up some good tips here

Should It Open a New Window?

Saturday, January 28th, 2006

One question I have been asking myself when writing this blog is - should external links in my blog open a new window by default, or should it stay in the current window? What is considered "best practice" nowadays? So I decided to do a bit of research. As usual when it comes to such topics the opinions are many and varied, and everyone thinks they are right. So I decided to share with the world my conclusions. :)

I have decided that it is best practice to not open new windows to external sites by default. Why?

  • New windows popping up can confuse inexperienced surfers who are used to the safety of the "Back" button. A new window does not retain the browser history of previous windows, thus rendering the Back button useless.
  • Experienced surfers know how to open new windows or tabs - let them choose. Tip: In Internet Explorer and Firefox hold down the "shift" key when clicking a link to open it in a new Window, or in Firefox use the "ctrl" key to open in a new Tab.

  • New windows opening up are a big problem for the visually impaired whose speech-to-text software may not have been warned of the window change, or they have missed hearing the warning that a new window was opened.

Of course, there are always exceptions to the rule. In some situations opening a new browser window is the logical thing to do - but not for every link by default.

If you do…

When/if you do want to open a new Window keep in mind that the target attribute of the <a> tag is deprecated, and will prevent your pages from validating in HTML 4.01 Strict, XHTML 1.0 Strict, or any future version. There are a number of alternative methods around - most of them using JavaScript. Here is the method I recommend:

<a href="http://google.com/" onclick="window.open(this.href); return false;">
  A Test Link
</a>

Here is a sample link using this code.

Why is this recommended method? It achieves our objective of opening a new window, but it also:

  • Preserves the href element for Search Engines
  • Users who want control can still right-click
  • The link can still be Bookmarked or added to the browser Favorites
  • Your code will validate

—————

So … future external links on this blog will not open a new window by default. And on the odd occasion it is a good idea, I will use the method outlined above.

If you have any thoughts on this topic I would love to hear them…

The Future of HTML: XHTML 2.0

Saturday, January 28th, 2006

W3C

XHTML 2.0 is the W3C's effort to fix inherent problems with HTML and to meet the growing requirements of web-based solutions. XHTML 2.0 takes the move toward XML to the next level and will try to acheive the following design goals:

  • Use XML as much as possible: Where a language feature already exists in XML, don't duplicate or reinvent it.
  • Structure over presentation: Thanks to CSS stylesheets, you no longer need explicitly presentational tags in HTML.
  • Make HTML easier to write: Remove some of the needless idiosyncrasies of HTML.
  • More accessibility, device independence: Make as few assumptions as possible about the way a document will be read.
  • Improved internationalization.
  • Better forms: Long overdue improvements are required!
  • Reduce the need for scripting: Include typical scripting usages in HTML itself.
  • Better semantics: Make it easier to integrate HTML with semantic Web applications.

Of particular interest to me is the goal of XHTML 2.0 to provide a declarative format for specifying user interfaces in a similar way to Mozilla's XUL or Microsoft's XAML. W3C will also define XBL2, a declarative language that provides a binding between custom markup and existing technologies. XBL2 will essentially give programmers a way to write new widgets for Web applications.

If you want to prepare yourself for the future an article on IBM Developer Works suggests the following:

  • Get serious about using CSS, and try to remove all presentational markup.
  • Think about how you can deploy microformats in your pages. (Microformats are a way to make human-readable elements in Web pages carry semantics that computers can interpret too. They are a bridge between today's HTML-based ad-hoc semantics and tomorrow's RDF-compatible XHTML 2.0 metadata.)
  • If you've not done so already, get experience with XHTML 1.0.
  • Experiment with the X-Smiles browser, an experimental platform with early support for many of the W3C's new client technologies such as XHTML 2.0, SVG, XForms, and SMIL 2.0 Basic capabilities.
  • If you create new client systems based on XHTML-like functionality, seriously consider using XHTML 2.0 as your starting point.

XHTML 2.0 is not likely to become a W3C Recommendation until 2007, according to W3C HTML Working Group Roadmap. Now is the time to start reading and experimenting with XHTML 2.0 - and prepare for the future!

For the full article from IBM Developer Works click here.

FireBug: The Ultimate JavaScript, DHTML, AJAX Debugger

Tuesday, January 24th, 2006

I only just wrote an article on Console² and I found something better - FireBug. FireBug is a new tool for Firefox that aids with debugging Javascript, DHTML, and Ajax. It is like a combination of the Javascript Console, DOM Inspector, and a command line Javascript interpreter.

FireBug is fairly simple - it adds a console to the bottom of every web page in Firefox. It enables the following features:

  • Mouse-over DOM Elements on the page
  • Type in JS expressions into the command line for execution
  • Inspect AJAX (XMLHttpRequest) responses as text or XML
  • Only show errors for the current page - previous data is cleared
  • Display JavaScript, CSS or XML Errors
  • Show a red dot in the Status Bar to indicate errors on the current page
  • Set preferences on what errors you want to see

If you are a developer you can even get your page to write directly to Firebug - instead of using "alert()" or other methods for debugging. There is even a tutorial on how to do this.

Yup, you have to install this one

The lazy way to create a Favicon.ico

Friday, January 6th, 2006

The favicon.ico is a small icon file that sits at the root of your website. It will display next to your website details in the browser address bar and in a Favorites/Bookmarks list. I have created a ICO file for this website which you should see in the address bar right now - it looks like this How did I create it? It couldn't be easier:

  1. Use imaging software to create your image 16×16 (pixels).
  2. Use the online FavIcon from Pics tool to convert your image to an ICO file
  3. Follow the instructions from FavIcon from Pics:
    - Download the ICO file
    - Upload the ICO to the root folder of your website
    - Insert the code in your HTML as described

Done.