About admin

Web developer since 1998 in Toronto, Canada

CakePHP Expandable Behaviour Tip

When YYZtech was being updated to use the VSS (Venue Storage System) from the previous system, it became clear that VSS needed to be updated as well. One of the original goals of VSS was that it could be a directory system for different kinds of things as long as they where physical venues of some kind and so they had certain properties like an actual address, hours they open to the public, etc.

As part of that, a way of storing “meta” information was needed, that is information that was unique to a venue or type of venue that not all would have, much like WordPress lets additional information about a post be stored in a separate table which makes, say, adding an ISBN number field to book reviews easy.

After rolling our own for several projects, Felix Geisendörfer’s Expandable behaviour was chosen because it was simple to set-up and use and it just worked. Hopefully CakePHP at some point includes a similar functionality as an “official” add on much like virtual fields was added in CakePHP 1.3

Which leads to a “gotcha”….
One issue combining virtual fields and the Expandable behaviour is that virtual fields can end up being interpreted as new fields by Expandable and Expandable then saving them. What’s worse, is that when the table entry is loaded, the virtual field and field from Expandable are combined with one overwriting the other.

This particular behaviour happened when we added a way of cloning venues, removing and replacing certain information along the way. The reason for this would be adding a chain store location; the address and phone number would change but the description or products sold probably wouldn’t. Now the table that stored the venues had a virtual field, full_name, that contained the name and sub-name of a venue (e.g. “Joe’s Bar”, “and Delicatessen” as “Joe’s Bar and Delicatessen”) which Expandable saw as a new field and saved the virtual field to its table and led to about 20 minutes trying to figure out if there was some kind of weird caching issue going on.

Anyways, the fix was to turn off the virtual fields like so:
$this->Venue->virtualFields = false;

…and that was the end of that problem.

Nexus One Update

The Day after Canada Day I was walking around Halifax and got a message on the Nexus phone that an update was ready to download.

By the size of it, it wasn’t a big surprise what it was: the 2.2 update (Froyo) had arrived. There aren’t a lot of obvious changes apart from some small changes to the interface, but most of them  seem to be under the hood. The much talked-about tethering (turn your phone into a WiFi hot-spot) is there, as are general speed improvements.

I also went to the market and downloaded the Flash player which means visiting a number of web pages is much more satisfying. In short, some new features, a bit faster, and nothing broke (yet) – I’m happy. Hopefully other Android users will be getting their updates soon.

Nexus One Experience

I’ve been using a Nexus One for about the last month on Fido’s network. Overall it’s a good phone and quite a step up from my previous, semi-indestructible, smart-phone; I say “semi” as, though the Nokia E62 handled being dropped numerous times onto pavement, torrential Toronto rain eventually did it in.

Nexus One is the AndroidOS phone that Google sold themselves up until last month, though they’re now looking to sell it through carriers over here as they’ve already started with mobile companies in the U.K. and points east. I haven’t had any real problems running on Fido, so based on my experience, putting it officially on Rogers/Fido would be a natural move – plus it’s a higher-spec. phone than Telus’ current Android models.

Setting up on Fido
While the Nexus runs just fine as a phone on Fido as soon as you pop in the SIM card, it’s not a Rogers/Fido phone so you have to set some things up yourself. For getting G3-speed data running, Brill Bappin has a great page at: brill.pappin.ca on getting the Nexus working on Fido.

Impressions
Overall, the interface is not as polished as the iPhone, but it’s definitely got more stuff in it. A case in point is WiFi; I use the free WiFi that Second Cups offers with BoldStreet networks, the problem I kept getting though with my iPod Touch was it seemed to get them confused when visiting several different Second Cups over a week. This wasn’t a problem with Android, in the odd time it got confused, I just hit the “forget” button under the connection to make it forget the old connection. On the iPhone my best guess is the Forget must be buried somewhere under the settings. On the downside, a lot of websites that seem to be only checking for iPhone and sending up the regular web page.

The camera shoots photos/video quite well during daylight. It has a auto-focus and a LED-flash, but that still doesn’t do much for night photography. One interesting thing is that it records location using the phones build-in location sensors. Using WiFi and the camera will eat up battery life and I find it needs to be charged about every other day with normal usage, though you could probably extend this by turning off WiFi/Bluetooth and background data-sync – all easily done from settings.

Software-wise, you can download apps right onto your phone – in fact, this is one of the things you get used to: not having to plug your phone into a computer to update files. Both Twitter, Facebook and FourSquare have free apps now.

Finally, one problem I had early on was with the on-screen keyboard going wonky. Google recommends: 1) make sure you’re not touching more than one place (including your sleeves), 2) turn off Nexus completely (hold down power switch, select Turn Off).

Apple: Back to 1984

It’s been widely reported that last week Apple made some changes to what tools developers can use to create applications for the iPhone and iPad. Blogger John Gruber also did a pretty solid analysis of why Apple did this: namely to keep developers developing applications that run primarily on the iPhone. I agree in the short-term this makes sense for them, but it seems like they’re forgetting some lessons.

What Apple is fighting is the commodification of a type of product, namely mobile phones and soon web tablets. This happened before to them: in the mid-1980s the Macintosh was quite innovative in terms of a user-friendliness, compared to the many of the personal computers available at the time. By the mid-1990s this had changed: Microsoft had created a “good enough” copy of the Mac experience with Windows and prices on hardware had fallen so that Apple’s products where quite expensive by comparison. The Mac continued to be popular in some circles, but had essentually became the Porsche that people bought calendars of before buying a Honda.

While the Porsche example is not perfect — people buy a high-end sports car for different reasons than they choose a phone — the challenges are not. Like Porsche, Apple has to protect its brand by demonstrating that there is a reason you are spending several hundred dollars on a phone. One of the ways it can do this by having lots of applications that are unique to the iPhone. One way to do this is make sure developers invest the time and money creating an iPhone application, and not spend that on writing for competing phones. The contract changes made last week which seem to be primarily aimed at Adobe’s Flash software are designed to ban technologies that would make it easier for developers to write applications that would run on several platforms, essentially making the iPhone’s offerings less unique. While I don’t anybody is going to be throwing their iPad into Boston harbour over this, it’s not going to help Apple’s image with developers any more than the ongoing issues with the less-than-transparent App Store approval process is doing. Short-term the effect is pretty nil, medium-term though it’s going to make the alternatives more attractive.

While the iPhone had become ubiquitous and in 2010 arguably still provides the best user experience of any smart-phone, its probably only a matter of time before someone, maybe Google, maybe RIM, maybe even Nokia come up with something good enough. Apple lost the PC market because it tried to be Porsche; Apple risks this happening again, but this time it’s not going to take 15 years.

Why no Buzz for Google’s Twitter

Google launched Buzz last week to generally better press than Apple received seems to have received for it’s iPad, though I wonder if there are some similarities. For one thing, both of these are kind of re-imagines of already successful products. The iPad is basically the iPhone on a grander scale; if you watch Apple’s videos it’s clear they are thinking, “This is what we did with the iPhone- but what if we had a bigger screen?” Google’s Buzz of course is kind of reminiscent of Google Wave which was promoted famously as “What if we where inventing email today?” Buzz might well be asking “What if we invented Twitter today?”

There’s plenty of ways that kind of thinking can go right or wrong, but I’m wondering if what made Twitter what it is today was that it was kind of retro to begin with- and that’s what makes it fun. I’ve tried to explain Twitter to people for about 2 years now. The 140-character limit is kind of arbitrary- text messages can be up to 160 characters and computers-type limits would be multiples of 8, resulting in numbers like 128 or 256 characters.  So yes, it’s a bit of a toy, but it’s limitations are what make it a challenge, you can’t be sloppy with Twitter, it takes a bit of thinking to pack much meaning into 140 characters –spaces and punctuation included– and that in turn that appeals to certain people.

Google Buzz does away with that limit of course.  While  Buzz of course has no limits on text, it lets you add photos, links, probably video too. It’s certainly probably more practical, but it might not turn out to be as much fun.

CakePHP database config quick-tip

Most CakePHP programmers have seen this simple way of storing the development and production database settings in one file:

  1. class DATABASE_CONFIG {
  2.     var $prod = array(
  3.        
  4.         'database' => 'live_mysite'
  5.     );
  6.  
  7.     var $test = array(
  8.        
  9.         'database' => 'local_mysite'
  10.     );
  11.  
  12.    // the construct function is called automatically, and chooses prod or dev.
  13.     function __construct() {
  14.         //check to see if server name is set (thanks Frank)
  15.         if(isset($_SERVER['SERVER_NAME'])){
  16.             switch($_SERVER['SERVER_NAME']){
  17.                 case '127.0.0.1':
  18.                     $this->default = $this->test;
  19.                     break;
  20.                 default:
  21.                     $this->default = $this->prod;
  22.                     break;
  23.             }
  24.         } else { // we are likely baking, use our local db
  25.             $this->default = $this->test;
  26.         }
  27.     }

If you haven’t, check out Edward A. Webb’s original post from 1998 2008.

This same technique can be used in the bootstrap.php file for other settings that change based on the server, for instance GoogleMap keys:

  1. if ( strpos( $_SERVER['HTTP_HOST'],'MySite.com') !== false)
  2.     Configure::write('GMAP_KEY', 'ABQIAA…qcPrtZgKHQ');
  3. else
  4.     Configure::write('GMAP_KEY', 'ABQIAB…e6qfWeeY8Q');

However, when baking a model, the database file only defines two types: prog and test so you pick one and end up with a model file with a line like:

  1. var $useDbConfig = 'test';

in your baked model that doesn’t cause any problems right up until upload it to your live server late one night and start getting errors about being unable to make a connection- guess who did that?

The solution is simple: just define a default

  1. var $default;

somewhere in the file, now when you bake cake will give you the option of using the default connection which won’t add any problem-causing $useDbConfig to your model.

Hope this saves someone 20 minutes :)

December ’09 Wrap-Up

This past December we launched 2 new websites serving the Toronto area and a re-launch of an older website.

Toronto-Gym.ca
Launched on December 27th, Toronto-Gym.ca is a directory of gyms, fitness centres and sports and health stores in Toronto and the GTA. A Vancouver version of this site is expected to be launched in early 2010.

TorontoIndustryNetwork.com
Toronto Industry Network is a group of manufacturers and manufacturing associations with operations in the City of Toronto. Collectively the Network employees approximately 35,000 people directly and another 100,000 indirectly through suppliers and customers.

Halifax-Restaurants.com
Halifax-Restaurants.com was re-launched after about a year-long break. This is a sister site to SimcoeDining.com that will be covering more places to eat in Halifax, Nova Scotia in the coming months.

Adding robots meta-tag to a CakePHP view

Here’s a little how-to I discovered a few months ago while I was working on SimcoeDining.com and realized that Google was indexing a whole lot of mostly blank pages.

To solve this, I figured I’d better put a no-index on those pages fast; after mucking around with CakePHP’s html->meta handler (because I wanted the meta tag in the header where it belonged) and not finding anything, I came up with:

  1. $html->meta('robots', null, array('name' => 'robots', 'content' => 'noindex') ,false);

BTW: The pages where empty at the time because there wasn’t a lot of data in the system, so a lot of searches where coming up empty- that’s been “fixed” now too.

Hopefully this saves someone else 20 minutes :)