Author: ccornutt

Is your site Quiet?

Here’s an interesting article I came across (digg) today for all those working with content heavy sites – Andy Rutledge on “Quiet Design”. In it, he compares two major online news sources – CNN.com and USAToday.com – in things like layout, object placement and things they could do to help achieve Quiet Structure over Loud Structure.

It’s interesting to see his opinion that it’s not always about dropping content on a page to make things simpler but that it’s also about where things are on the page and how they’re laid out compared to the others.

A Primer to Using Air – Followup

Well, I poked around in the AIR documentation, and I think I found their preferred method (and the only method I tried that would let me grab data from another domain) of connecting to a backend script:

[cc lang=”javascript”]

function appLoad(){
var request = new air.URLRequest(‘http://www.php.net/news.rss’);
var loader = new air.URLLoader();
loader.dataFormat=air.URLLoaderDataFormat.TEXT;
loader.addEventListener(air.Event.COMPLETE,completeHandler);
loader.load(request);
}
function completeHandler(event){
var loader2=event.target;
air.trace(loader2.data);
alert($(‘//rdf/item/title’,loader2.data).length);

$(loader2.data).find(‘item/title’).each(function(k,v){
alert(v.text());
});

$(‘item’,loader2.data).each(function(k,v){
$(‘#mytbdy’).append(‘

> ‘+v.childNodes[0].nodeValue+’

‘);
});
}

[/cc]

I think the code above’s a little flaky when it comes to inserting things back into the table, but the connection code is sound. It grabs the actual RSS file from php.net and pushed it into the table below it.

A Primer to Using AIR

Spurred on by some recent news and by the big push that Adobe is trying to make for PHP developers to get into Flex, I decided to try my hand at their newer (new to me anyway) offering, AIR the Adobe Integrated Runtime environment. The basic idea behind it is to allow web developers, without much more than the skills they already have, to make full desktop applications any user with the AIR runtime installed can use.

Thankfully, it’s pretty simple – once you wade through some of the documentation and find the section on creating a first application. Their example puts a div on a page and, when the application is started, pushes new content from a text file into that div. I opted for something a little bit more interesting and used something a little more handy than just regular Javascript – jQuery. There’s two choices for developers to go with – one for people already working with Flex and the other that I think most developers will follow, using HTML and Javascript (my path).

Construction of the application is surprisingly simple and consists of only three required files – a Javascript library they include in the SDK, the HTML file for the application to render and an XML configuration file to handle the application metadata. I wanted to do something more fun than their example, so I decided to go with a feed reader. It’s nothing big and it can only really real with RSS files (it should at least), but it is a pretty good example of how to get started.

First, we’ll look at the configuration file:



	My Simple Feed Reader
	feedReader.html

The XML Configuration File
The XML here is pretty simple but lets go through each line. The application container holds all of the settings for our simple app, both in the attributes and in the inner tags. The appId (capitalization is important here, as I found out later) parameter lets us give the application a unique name. In my case, I just gave it something simple that applied to the project. It doesn’t have to match up with anything else in the project. The next two parameters define the namespace and the version for the application. Inside of that, you can define a name for the application, something a bit more user-friendly and the look/feel of the app’s window (in rootContent – Note: for some reason the code highlighting plugin I’m using makes rootContent all lower case, but it needs to be mixed case for things to work). Ours just uses the standard “chrome” for whatever OS it’s on and defines the window as visible with a height/width of 400/200. Inside of the rootContent tag is the filename for the HTML file we’re linking this XML data to, the one that we’ll look at next:



	My Simple Feed Reader
	
	
	
		function appLoad(){
			$.ajax({
				type: "GET",
				url: "phpfeed.rss",
				dataType: 'xml',
				success: function(msg){
					$('item/title',msg).each(function(k,v){
						$('#mytbdy').append('<tr><td>&gt; '+v.childNodes[0].nodeValue+'</td></tr>');
					});
				}
			});
		}
	
	
	body { font-family: verdana, arial, helvetica; }
	td { font-size: 10px; }
	#titlebar { 
		font-size: 15px; 
		font-weight: bold; 
		background-color: #6D66FF; 
		color: #FFFFFF; 
		padding: 3px;
	}
	


	<div id="titlebar">FeedReader</div>
	<table cellpadding="2" cellspacing="0" border="0">
	<tbody id="mytbdy">
	</tbody>
	</table>


The HTML Document
This code is saved in feedReader.html and shows how to create the simple listing of titles from our RSS feed text file and print them to the application’s main window. This is where some of the real power of the AIR functionality comes into play. If you loaded this page up in a normal browser it would (almost) work perfectly. Web developers used to working with Javascript and HTML can pick this stuff up super-fast. I decided to use the jQuery library to help make things a little simpler (plus it’s one of my new toys coming from working with script.aculo.us/prototype and wanting something different).

Javascript & Parsing XML with jQuery
The Javascript uses jQuery’s Ajax functionality to pull in the file (no cross-domain requests so we’re limited to a local file) and run through it, parsing out the information in the title tags for each entry. In this example, the RSS is the feed pulled from the PHP.net website in the standard RSS format. jQuery uses a little XPath-ish magic and appends new table rows to the tbody of the table in the HTML below. The key to all of this, though, is in the body tag – the onLoad property. The AIR interface picks this up and executes our code automatically (inside of “appLoad”) so we don’t have to do a thing. Of course, in more advanced applications, you might not need this in favor of clickable items that fire off Javascript events.

Styling with CSS
Because the application is more or less a glorified HTML document, we can use CSS to style it. You’ll see that we styled things simply – the div up top to look like a header and some font styles and padding to make things look a little cleaner.

Building and Launching the Application
Having all the files is all well and good, but to make use of them we need two more steps – packaging the application and running it. Of course, you’ll need to have the AIR runtime installed to make the execution work, but you’ll also need the Adobe AIR SDK to compile the application into something usable.

Download the ZIP file and unpack it someplace useful so that we can get started. First, we’re going to test the application with a utility that’s a part of the SDK – adl:

/path/to/sdk_dir/bin/adl.exe /path/to/feedReader-app.xml

This will run the debugger against your code and error out if there’s an issue with the code. Unfortunately, in my experience, it only errors when there’s an application problem – not a problem with the code inside the app (like a Javascript error). There’s probably a way to turn this on, but I haven’t looked into it yet.

When that’s all well and good and passing tests with flying colors, we’re off to the last step of our little sample application – compiling the files into a package that can be shared and executed on any platform using the AIR runtime (you need to be in your project’s folder for this part to work without specifying paths for everything – it’s just simpler):

/path/to/sdk_dir/bin/adt.bat -package feedReader.air feedReader-app.xml feedReader.html AIRAliases.js jquery.js phpfeed.rss

If all goes well, you should end up with a neat little AIR package sitting in your directory that you can double click on and get the feedReader.air file in your working directory. Now, if you double click it, you’ll get this notification:

Click through to install it and you should now be able to run it with this as a result:

Wrapping it Up
Of course, this is by no means a complete tutorial on working with the AIR runtime – there’s tons more functionality and information out there on developing web-distributed desktop applications. Check out Adobe’s Adobe Labs section for AIR for lots of guides and other information.

I’m going to mess with things a bit more and see if I can figure out how to get the application talking to a PHP backend (that’s not on the local machine), so stay tuned for a second part to this tutorial. Oh, and please let me know if there’s anything in here that’s not working or doesn’t make too much sense – I know it’s a lot of information.

A Review of “PHP Programming Solutions”

I recently got the opportunity to be a tech reviewer for a book from McGraw-Hill by Vikram Vaswani (the CEO and founder of melonfire) titled PHP Programming Solutions. Needless to day, I’m a bit partial to it, but I still want to recommend it as a good, valuable addition to any developer’s library.

The book takes the “cookbook” approach rather than the how-to process of learning PHP. It assumes that you know a bit about what you’re doing, but are just looking for that helpful hint on that one chunk of code that’s evading you. It’s broken up into sections based on subject matter:

  • Working with Strings
  • Working with Numbers
  • Working with Dates and Times
  • Working with Arrays
  • Working with Functions and Classes
  • Working with Files and Directories
  • Working with HTML and Web Pages
  • Working with Databases
  • Working with XML
  • Working with Different File Formats and Network Protocols
  • Working with Exceptions and Other Miscellanea

As you can see, it just about leaves no stone unturned. One of my favorite parts about the book, though, was the way that it used what PEAR has to offer whenever it could. Several of the more complex examples revolve around the use of PEAR components (either on their own or linked together) to accomplish a goal. I think this approach is enough to set this book apart from some of the other “cookbook” style publications out there.

If you’re a PEAR developer, you’d do well to pick up a copy of this one and check it out. Even if you’re not, there’s some great tips in there that can help out in a pinch.

Little Baby Connor

Well, this is the first time that I’ve managed to get back to a net connection where I can add this new post, but I wanted to share with everyone the latest addition to our little family – Connor:

Book Review: The Design of Sites: Patterns for Creating Winning Web Sites (2nd Edition)

If you do anything on a website besides sitting in you chair only coding all day long, you owe it to yourself to check out a copy of this book from Prentice Hall – The Design of Sites. Now, I can almost feel the eyes rolling from here even at the mention of this kind of book, but trust me – pick up a copy and thumb through it and you’ll see the difference.

It’s not one of those “here’s what’s cool in web design right now” kinds of things. It goes a bit deeper than that and it looks more at the components and structure of a site rather than the things that you could slap onto the exterior to make your site a bit more trendy (Ajax revolution anyone?) Instead, it breaks things down into patterns that describe the bits that make a web site what it is.

Each of the patterns presented are components, like “order tracking and history” or “personalized content”, that can be swapped around and plugged together to make a site. Of course, a book full of these kinds of things could get messy, so they divided them up into chapters:

  • Site Genres
  • Creating a Navigation Framework
  • Creating a Powerful Homepage
  • Writing and Managing Content
  • Building Trust and Credibility
  • Basic E-Commerce
  • Advanced E-Commerce
  • Helping Customers Complete Tasks
  • Designing Effective Page Layouts
  • Making the Site Search Fast and Relevant
  • Making Navigation Easy
  • Speeding Up Your Site
  • The Mobile Web

It’s a long list of a lot of great stuff that could get hard to keep track of. Thankfully, they thought of this too and color-coded each of the sections. Then, inside of each, the design patterns all have their own shade of the color for where they fit. Using these colors (and a letter/number combination) , they reference the patterns beside some of the other related patterns. It’s a bit hard to describe without seeing it, so I’d recommend picking it up and flipping through it to check out the layout style alone (definitely well thought out).

All of the patterns are briefly covered in an overview chapter (to make finding what you’re looking for fast) and expanded out in the later chapters with descriptions, examples and screenshots. They don’t just describe the end result (like a “grid layout” or a “progress bar”) either. They explain the concept behind it and, if needed, get into a little design concept theory showing why the pattern would be used.

There’s tons of great stuff crammed into this book (weighing in at over 800 pages, not counting the Appendixes) – so much that I’ve really only scratched the surface of the content. Plus, for a book of its size, the cost is pretty good – $40 USD from a site like Amazon or Barnes and Noble.

So, “The Design of Sites: Patterns for Creating Winning Web Sites” – definitely pick it up and take a look. It’s nice to see a web development book that focuses more on making sites better rather than just making them better looking.

Oh, and a quick last note to the coders out there – don’t get this one thinking it’s going to be all about programming these patterns. It’s mostly a theory book with a dash of code thrown in here and there to show what they’re talking about.

The Results are In…

Well, no more being anxious about the Zend Certification Exam (taken two weeks ago – does that make me impatient?) – an email came today that sealed my fate for the PHP 5 version of the test…

I passed! 🙂 I am officially a PHP 5 Certified Engineer 🙂

Woo! It’s funny how, no matter how old you get, you always (well, I always) seem to feel the the same way after I’ve taken a test and am waiting on the results. Either way, it’s always a relief to find out the result – good or bad. Thankfully, it turned out good this time 🙂 Congrats to all of the others out there that took the test and are new ZCEs!

PDO + Oracle = Loads of Anti-Fun

Okay, so in playing around with some of the somewhat bleeding edge stuff (well, okay, so PDO isn’t that bleeding edge) on my development server, I’m trying to get Oracle support working for a simple script. It doesn’t want to seem to cooperate, and I just wanted to make sure I’m not doing something I shouldn’t be (or are forgetting something) – because it still dosen’t work.

Here’s what I’ve done so far:

  • compiled PHP 5.2.0 with:
    • –enable-pdo=shared
    • –with-pdo-oci=shared
    • –with-sqlite=shared
    • –with-pdo-sqlite=shared
  • Installed both PDO 1.0.3 and PDO_OCI 1.0 from scratch
  • Verified that the modules are in the “ext_dir” specified in the pnp.ini
  • added the lines to load them dynamically:
    • extension=pdo.so
    • extension=pdo_oci.so
  • When I make a phpinfo() page, it shows both that PDO is loaded and that “PDO Driver for OCI 8 and later” is “enabled”

And, of course, the code:

[php]
$sql=sprintf(‘generic SQL here’);
$arr=array(
‘oci:dbname=DBINTNSNAMES’,
‘user’,
‘pass’
);
$dbh = new PDO($arr[0],$arr[1],$arr[2]);
[/php]

This yields the lovely error message below:
“Fatal error: Uncaught exception ‘PDOException’ with message ‘could not find driver’ in /www/web/test/getbal2.php:36 Stack trace: #0 /www/web/test/getbal2.php(36): PDO->__construct(‘oci:dbname=PHIS…’, ‘user’, ‘pass’) #1 {main} thrown in /www/web/test/getbal2.php on line 36

Suggestions? Ideas? Is there something I’m missing?

A Look Back @ ZendCon 2006

Well, I’m back from this year’s Zend/PHP Conference & Expo out in San Jose, California and can honestly say I had a blast. I’ve talked to people in the past that have gone to other conferences and have had fun, but this experience was more than that for me. Not only did I get to listen to some great talks, but I also got to meet up with some of the people I write about every day on PHPDeveloper.org and have never gotten a chance to shake hands with – including Aaron Wormus, Chris Shiflett, Ben Ramsey, the attending #phpc gang, and various others (as I forced my t-shirts upon them).

As mentioned, the talks were great, and the conference planners did a pretty good job keeping dupes out of the schedule. There were some that overlapped a bit, but I think that just happened because of the wide range of some of the talks. Here’s some of the ones I attended:

  • Robert Richards – Advanced XML and Web Services
  • Chris Shiflett – Essential PHP Security
  • Eli White – High Volume PHP & MySQL Scaling Techniques (standing room only)
  • Chris Jones – The Experience: Faster PHP with Oracle
  • Aaron Wormus – Moving to PHP5 with Style
  • Jaisen Mathai – Efficient development Using PHP, JSON and AJAX
  • Ilia Alshanetsky – Caching Systems
  • Andrei Zmievski – Unicoding with PHP6
  • Sebastian Bergmann – Testing PHP Applications with PHPUnit
  • John Coggeshall – Create a Sophisticated Web Application in 45 minutes – Using the Zend Framework

Definitely a busy week, but all of the talks I went to were great. I even learned a few helpful hints from them. 😉 Overall, though, it almost made me feel back for still being stuck in PHP4 Land where I work. There’s so much more that PHP5 has to offer, and making a move to it wouldn’t be that bad *crosses fingers*. I already had a PHP5 install on the test side to work with – now it’s just a matter of really getting in and making the changes.

My wife came along with me for the week and we managed to get out and do a few things during the day and evenings. We managed to get out to a local attraction, the Winchester Mystery House to get the tour (we’d wanted to do the flashlight tour on the 31st, but it was all sold out) and, post-conference, went up to San Francisco for what was, quite possibly, the rainiest day of the whole week. It turned out good, though, and we ate at a wonderful little place off the main strip – Scoma’s – with some of the best lobster bisque I’d ever had.

Needless, to say, it was a great week, and here’s to hoping I get to make the trip back out there next year. I’d be good to see the familiar faces again, and to get to catch up on all of the latest developments in the PHP world. Thanks to Zend for a fun week, and thanks to the DoubleTree for the nice facilities, and, most important of all, thanks to Axis Open Source for the free WiFi. There’s nothing more frustrating than a internet-related conference without an internet connection…

A ZendCon T-shirt Wrapup

Update: if anyone happens to know if a cheap way to get things overseas from the US, please let me know. I want to send these shirts out, but I can’t seem to find a cost-effective solution.

So, I’m back from this year’s Zend/PHP Conference & Expo and am looking over the damage done to the PHPDeveloper.org shirt population (my wrapup of the conference will come in another post). From the looks of things, I apparently underestimated the correct size of the average PHP conference goer. I started off with 50 shirts of varying sizes (M/L/XL) divided up into mostly XL shirts. It seems, though, that most of the people that were given a shirt by the end of the week ended up with a Large size (not the XL like I had figured – no offense meant to the other coders out there).

So, as a result, here’s the tally of what I have left – out of the 50 t-shirts, there’s 23-ish (I owe one or two to different people) of them left to be up for grabs for anyone out there. It’s first come, first serve, so if you want one, get while the gettin’s good:

Medium: 8
Large: 5
Extra-Large 10

(I’ll try to keep this post updated as the shirts are dropped from the list)

All you need to do to get your hands on one of these shirts is to drop me a line and let me know your shipping information. There’ll only be a $7 charge on top of the shipping to help pay for the shirts. Donations of more are always welcome and will go to help the site directly.

If you’d like to see some “action shots” of the shirts and where they were showing up at the conference, check out these great photos:

And, of course, my personal favorite shot – when Cal got up and plugged the shirts as part of his announcements one morning (no, I didn’t ask him to – as much of a surprise to me as anyone).

So, if you’re interested in grabbing one of these shirts (see this other entry for some more detailed photos), email me and let me know.