As a developer who builds customized PHP applications for clients on a regular basis, I'm always on the lookout for new and interesting PHP widgets that could reduce the time I spend writing code. And one such widget is PEAR's Structures_DataGrid package, which provides a handy way to display, sort and edit structured data in a table.
This might not sound particularly earth-shattering to you; after all, it's not that difficult to write PHP code to display data in a table or even to sort it using different criteria. What makes Structures_DataGrid special, though, is how easy it makes the whole process - a task that might easily take a few hours to code manually can be accomplished in a little less than ten minutes using Structures_DataGrid. And that, in my book, is certainly something to write home about!
In this article, I'll be introducing you to the Structures_DataGrid package, showing you how it can be used to display structured data in tabular form. I'll be showing you how to hook it up to various data sources (including a CSV file, an RSS feed and an Excel spreadsheet), and how to format the resulting output so it's as pretty (or as ugly) as you want it to be. I'll also introduce you to some of the package's more advanced functions, which allow you to interactively page through, and sort, data tables with minimal effort.
As a community-supported open-source language, PHP enjoys the support of hundreds of dedicated developers, who are continuously adding to the available store of PHP libraries and knowledge. This support is most visible in projects like PECL, the PHP Extension Community Library and PEAR, the PHP Extension and Application Repository, which offers a robust, feature-rich collection of PHP widgets that can save developers a fair amount of time and effort.
One such widget is PEAR's Pager class, which offers developers a framework for breaking large data sets into smaller chunks, or pages, for greater readability or easier navigation. Pagination is important, particularly when dealing with result sets containing hundreds or thousands of items, because it allows the user to exert some degree of control over which segment of the data set is visible at any given point, and thus avoid drowning in a never-ending sea of data.
The interesting thing about pagination is that the program code needed to accomplish it is unlikely to change from project to project: once you've got it written and working to your satisfaction, you can recycle it for any other application that needs it. And using a ready-made Pager reduces the amount of code you have to write and test even further...and that's always a Good Thing!
Over the next few pages, I'm going to give you a quick run-down on the PEAR Pager class, together with a few examples of how you can integrate it with various Web applications while still looking calm and collected. Keep reading!
At the State of Iowa we recently published our own PEAR channel (sorry inaccessible to the Internet). Our intentions are that all our custom PHP libraries and applications will be managed through that channel. Better yet, we are even considering using PEAR for managing non-PHP libraries and applications...hey, PEAR doesn't care it's not PHP!
As a result I have produced two HOWTOs on our intranet: one for our system administrators and the other for our developers. I've condensed those down into this one HOWTO which is a bit more generic but still useful to anybody looking to establish their own PEAR Channel for the same purpose. My example hereon assumes that your PEAR channel is at pear.example.com.
Come along on the journey of a developer making their very first PEAR package and deploying it to a PEAR channel using a real-word example. Seasoned PHP developers will be packaging and deploying PEAR compatible packages in no time.
So you've finally finished creating a wonderful application...probably in PHP but for the purpose of this discussion it can be coded in literally anything (hint: PEAR itself requires PHP but can be used to package system written in almost any language). In the days of old, you'd tag the code in CVS, create a tarball and ship it over to the system administrator. Easy enough, right? But what if?
The PHP Extension and Application Repository (PEAR) is a collection of PHP packages built to ease the development required to build an application. V1.4 of the PEAR package manager introduced the concept of channels, which are a way to organize and deliver packages that can be installed with the package manager. This tutorial discusses channels, introduces and explains the channel.xml file, and demonstrates how to build a channel for distributing packages. Channels are ordinarily used to expose PEAR packages through the Internet, but enterprises can uses channels to make distribution of enterprise-specific PHP code easy.
In this tutorial
This tutorial introduces channels, which you can use for advanced package management in V1.4 and later versions of the PEAR package manager. The tutorial introduces some commands to use with the package manager for discovering, viewing, and deleting channels.
I wrote this tutorial to provide a base on which to build a custom channel server. Although a few packages are available for implementing a channel server, the server requirements may not work in your enterprise. The examples and steps here will get you going so you can implement a server that works for you.
Before embarking, look at the packages you wish to expose on private channels within your company. Consider their design and whether they can be used by people outside your company. The abundance and quality of PEAR packages is amazing, and I encourage broader contribution so everyone can take advantage of nicely written, reusable code. Information about how to contribute packages to the PEAR channel is available.
This tutorial uses a scenario in which a contrived company, which has the intranet domain example.net, has decided to build a private channel and publish domain-specific packages to the channel. The package used throughout is called Account, and it presumably contains classes and methods for dealing with accounts in a manner specific to the owner of example.net.
If you use PEAR::MDB2, you can set a custom debug handler and collect all the queries you execute for debugging and performance tunning purposes, as shown before. But what if you're using PEAR::DB? Well, since PEAR::DB doesn't allow you such a functionality out of the box, you can hack it a bit to get similar results.
This is a follow up to a question posted by Sam in my DB-2-MDB2 post. The question was if you can reuse an exisitng database connection you've already established and not have MDB2 creating a second connection.
In order to use PEAR Spreadsheet_Excel_Writer, you don't even have to own a copy of MS Excel; all the examples here work equally well with OpenOffice Calc.
Introducing PEAR::Spreadsheet_Excel_Writer
Wouldn't it be great if you could provide your customers access to downloadable numerical data in the form of an Excel spreadsheet? The good news is that you can, with PEAR::Spreadsheet_Excel_Writer.
The PHP Extension and Application Repository (PEAR) has a number of packages that can significantly simplify your network programming projects. This document lists 10 PEAR packages of specific interest to developers working in the network programming realm and explains how they should be used.
You've probably seen a lot of websites featuring long, detailed articles, which are split into paragraphs, each of them in a separate page. Users often prefer reading short chunks of text instead of scrolling a very long page (unless they want to print the page, then the opposite applies). In this tutorial, we're going to see how we can build an article pagination system, with a little help from PEAR::Pager.
Most of the time, iterating through nested PHP structures requires you to write a recursive function that travels through the hierarchy in a sequential manner, examining each and every element in it. But recursive functions are complex, messy things and most developers (including myself) don't really enjoy working with them. That's why, when my last project needed to scan a directory hierarchy for a particular file (a typical recursive-function task), I didn't even consider rolling my own code. Instead, I headed straight for PEAR and its File_Find class, which takes all the pain out of searching multi-level directory structures.








