Google gears and air are a good pair

May 28th, 2008

So when google gears was first announced the spin seemed to be challenging AIR. I never really was interested in google gears because everything I read about it seemed to fall inline with what AIR had to offer (though Adobe collaborated with the gears team to implement sqlite). In the keynote at Google I/O gears piqued my interest when a representative from myspace described how he used Google gears to add full text search to MySpace (though that should be available on the site natively but that’s becides the point). There areas where the web browser simply falls short and going the desktop application route is just overkill. I think gears  is a great middle ground  and really could work to the benefit of AIR because with great power comes responsibility. As much as I like AIR i am night going to enjoy having 30 AIR apps installed for the different sites I use.  I believe a big part of being a good developer is using the right tools for the job.

As3 rpc-lib update

April 16th, 2008

Its been a while since I updated the featured download (a year and 3 days actually)for the lib (the version in svn was always the most reliable). Thanks to everyone who sent in issues and patches.

Update:

So there have been a number of reports of an Illegal Override Error in the new version of the library. That seems to stem from some changes in Flex 3.  Unfortunately I don’t have Flex 3 but on the wiki page of the project jamesyjhu has offered a solution for Flex 3 folk (as soon as I get a build of this Flex 3 fix I will put it on the downloads page):

For people who are using Flex Builder 3, and have the “Illegal Override of XMLRPCObject” error, you need to:

1) import the project into flex builder 3

2) it’ll tell you that the project was made in previous version of flex builder. Select the “default” version (which is Flex 3)

3) Open up XMLObject.as, look for “setCredentials” and replace the function signature with: override public function setCredentials (username:String,password:String,charset:String = null):void

4) right below, find “setRemoteCredentials” and replace the function signature with: override public function setRemoteCredentials (username:String,password:String,charset:String = null):void

5) build it (automatically) and enjoy!

AS3 HitTestPoint (migration from as2)

March 8th, 2008

Basically at the most inconvenient time hit a snag on what should be one of the simplest things to do in flash programming perform what was in as2 a hitTest.

as2:
my_mc.hitTest(_root._xmouse,_root._ymouse,true);

Expected as3 equivalent:
my_mc.hitTestPoint(mouseX,mouseY,true);

or

my_mc.hitTestPoint(my_mc.mouseX,my_mc.mouseY);

As you would expect by now the expected version didn’t work for me and after spending time searching couldn’t figure out why what was visibly happening (my mouse over the object) was not registering by code.

My solution:
var tpoint:Point = localToGlobal(new Point(mouseX,mouseY));
my_mc.hitTestPoint(tpoint.x,tpoint.y,true);

My solution worked but I have no idea why the expected code didn’t. It should be noted that I was doing the test in a nested clip that belonged to a nested swf (realizing that’s the heart of the problem as I type this). Anyhue it was fixed and I was all about solutions that night so hope this helps others in a similar jam.

Zend_Db_Table issue

February 18th, 2008

So I must say I like Zend’s database layer the best so far. Good abstraction and I was able to build on it. One problem I ran into is when I changed the name of a primary key column (after some architecting). ZF caches the table’s metadata and that meta data is used to build row objects (I am using my custom dto). Because of the cached data things went wrong and I had to  head over to the abstract class  to see why things went wrong.  I have  done my  fair  share of data caching stuff and I am disappointed that as far as I can tell there is no easy way to invalidate the metadatacache (like setting a flag or something), but I am still hoping I just haven’t found it yet

Open Id already getting tainted?

February 10th, 2008

So I am a proponent of OpenID. While I haven’t been able to influence its use in projects at work (will not happen anytime soon) I have been trying to implement it into a blog cms I am writing to replace the one I am using now (wordpress is popular but lacking imho).  So I fire up my IDE and implement the Zend_OpenId component following these instructions. I head over to yahoo to try enable openid on my account so I can test out the Zend implementation. It’s easy enough to enable but I got this long url as an id and I begin to wonder “do they really expect me to remember this?” you can customize it but you are advised NOT to use your nickname in the customization becaues then your email address and yahoo id becomes obvious. Ok I tried to make up ANOTHER id to use in my custom yahoo open id implementation and it turns out it is already taken (I thought the idea of openId was to make things easier). I really want to get cracking on my testing so I just use the url that was generated. I head over to my test page and plug in the url and to my surprise it fails. I figure I did something wrong so I look over the example and it appears everything is in order. I head over to yahoo and check the url again and yep its correct. I then decide to read the instructions (yes I am a man) and low and behold you have to enter yahoo.com as the id (excuse me for making the logical leap that the url given to me is what should be used to authenticate like other openid producers). I try that in my example and it fails again. So I head over to another open id consumer and test out the yahoo method and it works. Now I am bummed because there seems to be a bug with the Zend component. Still determined I tried my example using the AOL openid and eureka my example works! This could be because of the protocol the consumers used, or totally something else but at the end of the day yahoo’s openid implementation is unintuitive and really didn’t enhance my login experience. With the recent announcement of more big names joining the party, I hope they don’t mangle what I thought was a really good idea.

As 3 Inflector

January 28th, 2008

I’ve been doing more back end than front the last 6 months, but I’m back in the flash game and looking to bring best things I liked about server side development with me. All this goodness will be incorporated in a MIT licensed library and I hope it will be useful to developers like myself. The first contribution to this lib is a class for inflection. The Inflector allows for pluralizing,singularizing,camel casing, underscoring, and humanizing words. I did search for and find an existing inflection class but I decided to port the CakePHP inflector which is more extensive and more accurate. Download Inflector.

Try it out here:

Cross browser compatibility getting better or worse?

January 25th, 2008

CSS is getting closer and closer to being correctly implemented by all browsers (IE8 passed the acid test) but life as a web developer is not getting easier. If you thought Safari on Windows was “cool”, web developers around the world shed a tear. Just because a software is labeled cross platform doesn’t mean that it behaves the same on all platforms. I am not sure if my latest gripe lies with the Firefox browser or the flash player but there is a bug in Firefox for Mac where if html content is overlayed Flash content the html content flickers. The fix? get rid of any flash elements from under html content (by masking out the content when mac firefox is detected or hiding the layers)

Remember the browsers that you support is not determined solely by the site audience but also by whatever the hell your boss/client uses.

Zend framework cake view rendering port

January 13th, 2008

So I have gone head first in using Zend framework. First order of business has been to port libraries/features to zend framework. One of the features that I have always migrated is CakePHP’s view layout structure. For CI I was fortunate enough to get a library already made but no such luck this time.

Installation:

  1. Download my very own library Ak33m Library (this will contain all the libs I have made to enhance my zend framework experience).
  2. Extract the library to the location where you zend framework library is located. Sample layout:
    library (folder containing all libraries) -> Zend(zend framework)
    library (folder containing all libraries) -> Ak33m (my library)
  3. Add some lines to your bootstrap (for most people index.php. NB the library folder containing the framework files and my library should set to the include path at the top of the bootstrap file) to make the cake view renderer your default view renderer. (NB I am only doing it in the bootstrap because this is the most convenient place)
    [php]
    //Get the view renderer helper that injects the view object in each controller
    $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(”viewRenderer”);
    //replace the default view object (Zend_View) with the cake view object provided in the Ak33m library (Cake_View)
    $viewRenderer->setView(new Cake_View());
    //This is optional, but if a full CakePHP implementation is desired change the view extension for view files to ‘thtml’
    $viewRenderer->setViewSuffix(”thtml”);
    [/php]
  4. In the application->views folder create two subfolders (there are methods to set custom paths for layouts and elements these are just the default paths):
    1. layouts (application->views->layouts) - This folder is where the view layouts will be stored.
    2. elements (application->view->elements) - This folder is where the elements for a view will be stored

Usage:

The Cake_View object is a cross between Zend_View and CakePHP’s View object. You can use Cake_View just as you would Zend_View (see the zend documentation for details of view integration in zend) and to make use of the Cake aspect before you render your view simply set the layout that your view should be rendered in. Below is a sample IndexController.php that illustrates the most basic usage:
[php]

require_once ‘Zend/Controller/Action.php’;

class IndexController extends Zend_Controller_Action
{
/**
* The default action - show the home page
*/
public function indexAction()
{
$this->view->setLayout(”2column”);
}
}
[/php]

Next order of business is to create the 2column layout. A layout is a re-usable presentation that wraps around a specific view. In this example a 2column.thtml file is created in the default application->views->layouts folder. The code that goes in that file is here:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”><head>
<title>Cake Rendering Example</title>

<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />

<style type=”text/css”>
* {
margin: 0;
padding: 0;
}

body {
font-size: 62.5%;
font-family: Garamond, sans-serif;
}

h2 { font-size: 4.0em; }
p, li,h1 { font-size: 1.8em; }

.clear { clear: both; }

#header {
background: #;
padding: 15px 0 15px 15px;
}

#content {
padding: 15px 30px 0 0;
}
#main-content {
margin-left: 175px;
max-width: 600px;
}

#sidebar {
width: 145px;
float: left;
padding: 0 0 0 15px;
}
#sidebar ul {
list-style: inside;
}

</style>
</head>

<body>

<div id=”header”>
<h2>Zend Framework Cake View Rendering Example</h2>
</div>

<div id=”content”>
<div id=”sidebar”>
<?php //renders the sidebar elements with this items array to populate the menu items. NB $this->element(”sidebar”,$somedata) could have been used?>
<?= $this->renderElement(”sidebar”,array(”items”=>array(”home”,”aboutme”))) ?>
</div>

<div id=”main-content”>
<?php //$content for layout is where the view’s content will be rendered?>
<?= $this->content_for_layout ?>
</div>

<div class=”clear”></div>
</div>

</body>

</html>

In this layout an element called “sidebar” is rendered with an array paased to it (an stdClass object can also be passed as well).

[php]
renderElement(”sidebar”,array(”items”=>array(”home”,”aboutme”))) ?>
[/php]

For this element to be rendered a file named sidebar.thtml should be placed in application->views->elements. The code for sidebar.html is:

<h1>Side Bar Element</h1>
<ul>
<?php foreach ($this->items as $item):?>
<li><?=$item?></li>
<?php endforeach;?>
</ul>

The second parameter of renderElement is the data that is passed to the element. The array keys(or properties if an object was passed) of the second parameter are made into variables of the element view. So in our example the array value for “items” can be accessed within the element using
[php]
$this->items
[/php]

Because it is a tutorial it may seem harder than it really is but for the benefit of those following along the files used can be found here. For more information on how the Cake View works check out the original documentation here

OpenID support coming to Zend Framework

January 9th, 2008

So I just got another reason to validate my move to zend framework. For some it may be minor but for me it is major because I have been wishing for this since I didn’t want to have to build another custom library component. OpenID support is coming (the documentation is already up) and it is another well made component of the Zend Framework. This is another major plus I think in favor of using the framework not just because of the OpenID support but for how quickly components are being made available in the core of the framework (and it being core is especially nice because you can be sure that it adheres to the high standard under which other components were developed, coming with PHPUnit test cases and all). For those who are already using the Zend Framework you will be glad to know that it can be tied into Zend_Auth (which is Zend’s authentication component).

Zend Framework

January 6th, 2008

So here I am writing another PHP framework post. Fortunately I think I have covered a lot of ground with previous trials (the previous framework posts were based on production level websites) and I am just about ready to call it day. From day one when looking at frameworks I had my eye on the Zend framework. The biggest things against it was that it was not production ready and that wasn’t acceptable for production level websites. In August 2007 the framework went to version 1 and I have only gotten the chance to get down and dirty with the framework.

I am only just getting fully into the framework so this is not a comprehensive pros and cons just what I have come up with so far.

Pros:

  1. Developed by the creators of PHP (Zend). That in itself I think is a big deal especially when it comes to selling the idea of a framework to in house developers as well as to the stake holders
  2. Loosely coupled and easy to customize. The components of the framework can be used independently of the framework (I have used Zend components with Code Igniter). The customizable part is extremely helpful when introducing the framework to a team. If there are cool things that your team wants to retro-fit that shouldn’t be a problem
  3. When you get into the framework you realize that it benefited from careful planning. The framework is feature rich, well documented and the level of extensibility could only be achieved with careful planning (there are even PHPUnit test cases that can be very helpful for those of us who like to make customizations.

Cons:

  1. The framework requires PHP 5 .1 and greater. This will rule it out for projects that are to be hosted on servers that may be running PHP 4 (PHP 4 is no longer supported).
  2. Some of the things that come out of box with other frameworks isn’t present in Zend Framework. There are I think a lot of gluing together of pieces involved and that may require a little my time spent reading documentation etc etc (e.g. you have to write your own bootstrap where as other frameworks I have used give you a bootstrap in the form of a index.php).

Thats all I got for major pros and cons at this point but I may make additions once I have a project completed with the framework. Before I can make Zend Framework my framework of choice I have to add my own flare that will incorporate the best of previous frameworks I have tried as well as other libs that I find useful in my regular development. To that end a list of things that I are going to be equipping my basic build with are:

  1. CakePHP style view rendering. I really like the whole layout/view/element scheme that CakePHP uses. I was able to find a lib that did something similar for Code Igniter but had to roll my own library for Zend framework. Next Post I will be including the details of that custom library.
  2. AMFPHP for flash remoting. While I have been doing a lot of backend recently I still do flash and AMFPHP is still the way to go for backend to front end in my eyes (I am so excited about BlazeDS and hoping for some things to be ported to AMFPHP). I had somewhat of a hard time blending it with Code Igniter and so far putting it in Zend has been equally as challenging (and what I have so far requires a lot of icky hacks). When I get it to a point where I can consolidate as much hacks as possible and its been tested I will have a post on that
  3. Scaffolding CakePHP style. This is another neat feature from CakePHP I would like to replicate. While I have found that I dont really use it so much, I can see its usefulness when working with a team.
  4. Profiling tool. This is a nice to have. It would be a widget that you can append to your views that would have a lot of useful information about the view that was rendered. This isn’t some new idea (the company I work for had one built to aid development for a project) but unfortunately there are non available (as far as I can tell) out in the wild and I may have to develop it myself so that I can share with others.

Looking forward to banging out some good stuff with this bad boy and hopefully my future posts will exhibit the same enthusiasm :)