4/26/2006

To Generate or To Template

that is the question ...


read some of my ramblings on the subject here


and vote here!

4/19/2006

Talkin' AJAX at CHI PUG

I think this is the biggest Chicago PHP Users Group meeting I've been a part of, I believe I counted 15 people in attendance. Attendees were left to entertain themselves with pizza, beer and conversation while Rich, few others and I dealt with the technical difficulties so common at these things. Which would of probably been minimal if I had remembered that on my Uber Cool Laptop, I have no archaic VGA port – but only a DVI port and my The full dongle was sitting at home! DOH. So, we tried to load my files to my thumb drive which when plugged into Rich's cute little laptop...didn't like to read. DOH. So I tar-gz my files and ftp to my server.. then attempt to download to Rich's laptop. His laptop wouldn't untar the files. DOH.

So I put my font size real big on my laptop and set up on a stack of books and said lets go with a 17 inch widescreen display and offered my glasses to anyone sitting on the back. I have a sweet screen thats easily viewed from all angles.. so I guess it was not too bad. Better than nothing or using mime to present AJAX. Which I did in college. For all of 3 weeks.

Although I don't think anyone present was unfamiliar with AJAX, I showed Google Maps, a Sudoku creator/solver and TurboDB. Someone mentioned Weboggle and explained how that worked and I went to the site so folks could see.

I started with the method I use when I learn something new. I start with the most simple example, then build on it. The first example was just loading a plain text file via AJAX and displaying in a div. From there, I did an example calling a PHP file that created a list of files. Then I introduced Prototype, a Javascript AJAX library that makes the code so much cleaner and easier to use. Its include with Ruby on Rails, but you can download and use it totally seperate. The Ruby Kids can't have all the fun! Some of them had not seen the uber cool $() function that Prototype gives Javascript. Its essentially this;


function $() {

var elements = new Array();

for (var i = 0; i < style="margin-bottom: 0in; font-family: courier new;"> var element = arguments[i];

if (typeof element == 'string')

element = document.getElementById(element);

if (arguments.length == 1)

return element;

elements.push(element);

}

return elements;

}

(cut and pasted from prototype 1.5)


so instead of

document.getElementById('messageID').innerHTML = 'foo';


you can simply use

$('messageID').innerHTML = “foo”;


It takes either a string of an id, or an array of ids and returns the object reference to them (or array of references). Now why didn't I think of that. Nifty.

Folks pointed out that the property “innerHTML” might not be 100% cross browser (Heck with that, if it doesn't work in Firefox, eat my shorts!) and that you should use appendChild. You have been advised.

I illustrated the Ajax.Request object, that allowed you to set a function to call when the data is loaded, and a function to call if there is an error. The Ajax.Update object takes the name of the id to display the results in, and a function to call if there is an error. Most of the time, all I want to do is display some result in a div, so I use this one. Someone in the group said that Ajax.Request was all they used.

NOTE: Remember to use keyword "new". So you won't be like me, in a near panic 3 hours before presenting trying to figure out why I'm so dumb that my simple AJAX thing doesn't work. Error message in Javascript console: “this.initialize has no properties” Line 20 in prototype.js. HUH?! I should of remembered to search Google with my error message first thing.


Like this:

var result = new Ajax.Updater(

'messageID',

url,

{

method: 'post',

parameters: "color="+text_color,

onFailure: reportError,

});


NEW NEW NEW NEW ... maybe now I'll remember. Or in 2 weeks google for my error and find this post.


Then I showed what would happen if there was an error. My error reporting consisted of dumping the ugly http error in an alert box. Not recommended for production.


Finally, I showed a simple example of sending a value with ajax to a php file which returned a result. Which Larry was quick to point out was not checking the variable from the user.


Well of course. I am smart enough not to XSS myself in front of a room full of geeks. :P


Oh and thanks for the swag “Harper The Amazing” brought from his company ExtraTasty.com .. shot glasses and tshirts ... awesome!



Sample Files from Presentation:

ajax.tgz
ajax.zip (for you windows peeps)


Links

Prototype

Prototype Documentation

edit: fixed link to ExtraTasty.com

DC PHP Conference - Announcement and Call for Papers

PHP in the Federal Enterprise and the World: Secure Solutions for Federal Agencies, IT Companies and Non-Profit Organizations

We are hosting the first DC Metropolitan area PHP Conference this October. Not only that, but since we're in a unique location with opportunities and potential impact like nowhere else in the world, we're taking a slightly different look at PHP. Our mission is to demonstrate and teach how PHP is a solid, sensible, cost-effective, and low risk development language to use for government and non profits.

Therefore, our Presentation Tracks fall into four areas:

  • Integrating PHP with Federal Operations and the Enterprise
  • Security & Accountability
  • The Art of PHP
  • The Business Case for PHP
The Call for Papers ends on July 7th and gives suggested topics in each of these areas. Your presentation will be up to 400 people including decision makers for some of the largest and most influential organizations in the world.

Additional Information available:

  • As of last week, the Sponsor/Exhibitor Prospectus is available. We are already in discussions with a handful of major players in the Open Source/Government areas, so if you're considering, don't wait too long.
  • Also as of last week, the Call for Papers is open. As noted on the first page "Overall, strong preference will be given to sessions where real projects, actually deployed in business settings, are used to illustrate the topics being discussed". Translation: If you are successfully using PHP in a production environment in a government agency, you will be given special attention.
  • For those interested, we will have banner available which you are welcome to share, post, etc:

If you have any questions or comments, don't hesitate to drop a note to (keith at CaseySoftware.com).

4/15/2006

Never a dull moment

First of all, thanks to some howtos at http://wiki.ubuntu.com I was able to get my video drivers setup. Now I'm basking in 1680x1050 glory. I can have windows side by side -- almost... i usually shrink the window a bit. Very nice. People have asked me about my laptop, I got it from PowerNotebooks, this model. At the recent group meetings I've been at, people go "Wow .. thats some laptop!". In fact on the train ride to the perl meeting, Josh McAdams whips out his cute little 12 inch mac, brian d foy his mid sized mac.. and here I am with my honking thing! I said look: daddy bear, momma bear and baby bear! hehe.. it was funny.

Last friday night and saturday I was at the Cit-Con testing conference. It was great, they had a variety of topics and although some weren't really in my line of work I found them interesting. I got to talk to Jason Huggings, author of Selenium and Andy Lester, owner of the perl package WWW::Mechanize. They did a "Battle of the web testing packages" of some sort. Andy talked about Mech, and the advantages over Selenium...then Josh defended himself and talked about the pros of Selenium.

While I was there, Pete helped me with my laptop. I couldn't install Perl modules and I wasn't sure why. He looked at it and said I needed cc or gcc. So along with more help from Andy (I'm sure they were tired of me by end of day) I was able to get it installed..and off I go. I've installed Mechanize and tried it out, pretty nifty.

The following Tuesday, I went to the UniForm Chicago SIG Perl Meeting where Josh McAdams gave an extremely interesting talk on Perl::Critic, which will check your code for standards suggested in the Perl Best Practices book (very good read, even for PHP programmers). Very handy, I'm sure I will be using it alot. We had some fun and ran it on brian d foy and Andy Lesters code. heehehe.. they did ok :)

Now that I've been able to install Perl modules, I've been playing around with Andy Lesters How We Doin' module. Kinda nice.. can't get GNU Plot thing to work, I'll keep trying :)