Author: ccornutt

Baby Steps from ZF to Cake

So, I’ve been playing with CakePHP lately for a project I’m working up. I have to admit, it’s nice – very nice. I can see what all of the fuss is about.

Having used the Zend Framework for a project (a pretty important one, at least to me), I’ve had a bit of experience with the whole MVC style of development. I understaood what the parts did and how they fit together, but the actual development process was still a bit of a mystery to me until I really got into the ZF. I developed my application, worked up a pretty good site, and had things going along swimmingly.

Then I figured I’d give another framework a try for this other project. So, being the (brave?) soul that I am, I switched over to Cake. I have to admit, right off the bat, I almost ran screaming back to the Zend Framework. I was faced with a fully installed framework with a different structure than I was used to, different naming conventions and locations than I knew, and one big thing I wasn’t used to using coming from Zend – models.

So far, I’ve only used the models to act as interfaces to the database tables of their same name, but I know there’s more to them than that. Those working with the Zend Framework might not quite get how they’re used if you’ve never done any other MVC work outside of the Zend Framework, so here’s a bit of a basic summary as best I can tell:

Models are a “go between” for the controller and the view. The controller can look at and use the view to understand what the resource is like behind the scenes and use that to run code to output to the view. In the Zend Framework, since models aren’t even there, pulling information from and pushing data into database tables requires ensuring you have your SQL statements right to make the updates. In Cake, it’s as easy as calling the save() function in the controller and letting the framework (including the model for the table) so the rest.

Switching from one to the other was interesting – naming conventions and locations are less important to the Zend Framework as they are to Cake. Cake has a place for everything and everything in its place. There are directories under the views for the pages of each controller, helpers for each of the MVC components (components for controllers, helpers for views, and behaviors for models), and plenty of “magic methods” to go around.

I know I’m only getting started with Cake, but I do like what I’ve seen so far, and I know that there’s so many features of the framework that I’ve only touched on, but I’ll get there. I promise.

Oh, and, in a parting note, I have to compliment both frameworks on doing an excellent job on documenting their functionality. There might be a few little issues here and there, but over all, they both make life a lot easier through a few simple web pages.

I’ll Be There, Will You?

Well, it looks like I’m going to make it to some conferences this year after all (thanks to an understanding boss). They’re both right there next to each other, so it’ll be good to have it all right there.

First up is this fall’s The Ajax Experience put on by the guys at Ajaxian.com and the No Fluff Just Stuff Java Symposium Series. I’m not going to be speaking or anything, but since I write for the site, I’m going to be helping out with things. It’s running from October 23rd through the 25th up in Boston, Massachusetts, and if it was anything like the other one earlier this year, there’ll be some great speakers and great developers attending.

They’re still looking for speakers for the event, so if you’re up for giving an Ajax-related talk (preferably Ajax and PHP, but it doesn’t matter too much), check out this page for more details and the email address of where to send your talk information.

The next up, of course, is actually later that week – the Zend/PHP Conference and Expo happening out in San Jose, California. Thanks to the kind people organizing the conference, I’ll be one of the “press” attending the event. I’ve also taken out an ad in the conference program, so if you attend you’ll have to look for the PHPDeveloper.org 4th page ad. They haven’t posted the list of speakers yet, but I know it’ll be some good stuff – it always is. The tough part will be choosing which talks to attend.

I might also be doing some shameless self-promotion while I’m there. I was thinking about making up some shirts (something black with a simple logo-based design) to pass out to those that would want them. Think anyone would be interested? At the very least, it’d be fun to wear one myself during the conference. I’d stick out pretty well then, I guess…

Anyway, hope to see some of you out there at either of these conferences. I shouldn’t be too hard to find if you want to stop me and say “hi” while you’re there. I love meeting people that like PHPDeveloper.org….

php|tropics 2005 Pictures Flickred (yes, 2005)

So, I’m an (extreme) slacker and, spurred on by Cal posting his photos of this year’s OSCON, I proudly present to you something over a year too late:

My pictures from the php|tropics conference back in 2005.

Yes, call me a slacker, but I finally got them out there – few thought they may be. There’s only a few shots from the actual conference and more outside of it (go figure), but it was a great conference with tons of informative content.

Akismet is My Hero (including code!)

I’ll just start off with it – comment spam sucks.

Well, okay – really, any kind of spam sucks, but comment spam has been the bane of my existence lately. Initially, just to stop the incoming flow, I resorted to keyword matching. I grabbed strings from the current comments (around 6 thousand of them) and put them into a big array to help blog the evil little baddies hellbent on posting their worthless crap all over my comments (me? bitter? never!)

Sure it works, but it’s a pain to have to go back in each time and readd something when a new spam comes along. So, I told myself, “Self, surely there has to be a better way”. All hail the happiness that is Google – I found an answer within the first few pages of results, and that solution’s name is Akismet.

Now, I know what you’re thinking, “That’s just a WordPress plugin, right?” Wrong. They actually have a pretty slick (and simple! yay!) API to interface with their vast repository of spam-related things. All you have to do is provide them with the contents of the comment you’ve just recieved and they give you a “yay” or “nay” as to if it’s spam or not. The API takes in a traditional POST request and returns a normal response, in this case with either the string “true” or “false” (true meaning that it is spam).

Since it is a pretty easy interface to work with, I decided to throw together a little PHP class to make the connection and check to see if the message is spam (as well as check to see if your WordPress key is valid). Oh, did I mention that you need a WordPress key to get the setup working? You’ll need to go signup over on WordPress.com and, once logged in, go to your “My Dashboard” (top left link), go to the “Users” tab at the top, hit “Your Profile”, and right there at the top of the page you’ll see “Your WordPress.com API key is…”. Easy as pie.

With that in hand, you can grab the PHP class and go to town. What’s that? You want to know a little bit more about it? Well, okay…but just this once. And because I like you.

The class (made for PHP5, but is pretty simple to go back to PHP4 with) basically has seven functions:

  • Akismet() – the constructor, it just sets some class variables
  • _makeRequest() – actually does the work of sending the data off and getting the response back
  • _encodeRequest() – a simple function that loops and urlencodes an array
  • checkSpam() – generates the request to send off to the API to see if something is spam
  • checkKey() – calls a different server to see if the WordPress key you’re using is valid
  • submitSpam() – placeholder, for now.
  • submitHam() – placeholder for now.

Most of the class is pretty self-explanitory and is made to be used by just calling checkSpam() with the right parameters. As their documentation mentions, the more information you send along the better, but the simplest call I’ve seen that’s valid sends the content and author fields (comment_content and comment_author). The other fields that you can send are also listed in the documentation.

I know you’re hungry for some actual code by now, so we’ll get to the point. To make a simple checkSpam() call, here’s an example:
[php]
$arr=array(
‘comment_content’=>”viagra-test-123″,
‘comment_author’=>”enygma”
);
include_once(“/path/to/Akismet.php”);
$ak=new Akismet();
if($ak->checkSpam($arr)){
echo “this is spam and it sucks!”;
}else{
echo “we have an all-clear!”;
}
[/php]

Pretty easy, right? And any of the other fields you add into $arr (like permalink, comment_author_email, or comment_type) will be automatically included in the POST request out to the Akismet service.

It’s not the most robust system and there’s some other classes out there that are more well-developed than this one, but it’s light, easy, and it worked for what I needed it to do. Hopefully, it’ll help someone else out there too…

Oh, and incase you missed it – source: Akismet.phps

HeroesUnite.com

In another bit of shameless promotion…I’ve started another new blog concerning the upcoming (awesome) TV series on NBC – Heroes.

They thought they were like everyone else… until they woke with incredible powers. In Japan, a lowly office worker can teleport at will. In New York, a struggling artist can paint the future. In Los Angeles, a discontented beat cop can hear the thoughts of others. Elsewhere, a high school cheerleader discovers she is unbreakable and a single mom realizes she has a powerful alter ego. Heroes chronicles the lives of these people and the lives of others like them รขโ‚ฌโ€œ whose destiny just might be saving humankind.

I’m going to try to keep up with the show each week and write up some posts surrounding it. It’s already been compared to Lost as far as a serialized drama with “twists and turns around every corner”.

From DivX to iPod in Two Easy Steps

It took me a while to figure this one out, so I thought I’d share. Note, this is a Windows-only solution. I haven’t looked for converters for other OSes, but I know there are some nice ones out there:

I was looking for a way to take the divx videos in my collection and somehow treansfer them to my (shiny new) iPod video. You’d think it’d be an easy enough task, right? Well, I took a path that had many wrong turns and some ventures into bad places, but I finally came out okay. The main idea here was to take the video, convert it to a mp4 file that the iPod could play and retag it so that it shows up under the “TV Shows” list in the menu.

It’s not a one-click process, but it’s pretty close and it only involves two different pieces of software that are both free to use however:

  • Videora iPod Converter – This handy little piece of software can take a divx file and push it back out to you as an mp4 with a ton of different encoding settings. The interface is nice and friendly, and there’s even a “One-click Transcode” button once you have your settings down. It supports various languages for the interface, and you can even set up your own profiles to tweak your video output settings even more. It’s freeware, but I’d definitely donate to the cause – it’s one of the simplest/easiest converters to use
  • Win-AP – This handly piece of software does the magic of tagging the outputed mp4 file to work with the settings on the video iPod. Mainly what I was looking for (as I mentioned) was the ability to get my videos to show up under the “TV Shows” list on the iPod. Win-AP makes tagging the file simple, with fields for all sorts of information – Name, Artist, Album, Show, Episode Number, Season Number, etc. There’s no way to batch the tagging, but it’s still a handy little app.

It’s not too hard to figure out how it all works – once both are installed, you fire up Videora and point it at your divx video. After a while (depending on your system, maybe a long while), you’ll have a shiny new mp4 file sitting in your output directory. If you didn’t mind it not being tagged or anything, you could put that on your iPod right now. Me? I like to keep things organized, so I fire up Win-AP to get the tagging work done. It can create a backup file for the video it’s working with as well.

There’s tons of other ways to do this out there, but this was the first easy one I found…so enjoy!

Links:
Videora iPod Converter
Win-AP Show Tagger

jumpermovie.info

So, I was listening to one of my favorite podcasts the other day (Slice of SciFi) and they mentioned something about a new movie that’s just been put into production – ones based on a book I’d only recently read (well, it’s been maybe 6 months, but that’s recent, right?) by Steven Gould – Jumper. I adored the book, so, needles to say, I was ecstatic when I found out about the movie.

The (very basic) story of the book is:

A smart kid with a tough family life discovers that he has the ability to teleport. Empowered, he leaves home for NYC. While using his abilities to track the man he blames for the death of his mother years earlier, he draws the attention of both the NSA and a possibly nefarious guy his own age who has the same abilities and enters into a dangerous game of cat and mouse with both.

So, in an effort to share this great book and just general information about what I see to be a really cool little movie, I’ve created a site to keep those concerned up to date – jumpermovie.info.

So far on the site, I’ve gathered up some of the production details of the movie and some quotes from Gould himself off of his blog. I emailed him about the site earlier and he was gracious enough to come over and post a few updates/comments to the posts already there…

Coastr: the Social Guide to Beer

By the way, on a quick un-PHP related note, if you haven’t seen Coastr yet and are a beer fan, you should check it out. It’s actively in development, and it’s a pretty cool idea – social “beermarking”.

Coastr is an experiment in social networking for beer snobs (meant as a compliment, of course!). The basic idea is for you to create a list of your favorite beers, and to connect you with other people with similar tastes. And those connections will help you discover interesting new brews that you might have not known about before. “Social beermarking”, if you will.

I’ve been adding stuff like crazy and I mentioned it the other day over on Ajaxian.com for the simple, site-enhancing Ajax it incorporates. It’s built with Ruby on Rails, but there’s nothing there that couldn’t be done with PHP.

Coastr: the Social Guide to Beer

03.08.2006: Just a quick update…it seems that he’s added another new feature to the site – the “My Drinking Buddies” section on the “My Page” for each user. It connects users by the beers that they have in common (showing the people that you have the most in common with). Very cool ๐Ÿ™‚ Keep up the great work Brian!