Archive for the ‘Web development’ Category

On the pitfalls of date validation with the Zend Framework

Monday, June 21st, 2010

I'm writing this post as a warning for people using Zend_Date to validate dates, either as a standalone or as a validator in a chain. I've been using Zend_Validate_Date validator, which uses the Zend_Date::isDate() method internally, for a while now - mainly for form processing.

I've recently completed a project where a very bizarre bug would occur on some machines, and I wasn't able to reproduce it myself on any test machine that I tried. The bug manifested in a calendar system we built for the project, and in certain situations form submissions would not pass the date validation through Zend_Validate_Date, despite using the exact same input that was passing on the test machines.

After bringing in one of the "affected" machines for testing, I used the process of elimination to determine the problem originates in the Zend_Date::isDate() method, which has different behavior on different machines.

Zend_Date tries to validate dates according to a given format (with a default fallback). The dangerous behavior is that it tries to convert the given format to a localized format using Zend_Locale. Zend_Locale attempts to detect automatically the locale of the requesting client, and it appears that on the machines that were exhibiting the bug, a different locale was determined than those I was testing it on.

Despite trying to validate a non-localized format (to be exact, the MySQL timestamp format - YYYY-MM-dd HH:mm:sss), it was being converted on the affected machine sdue to the auto-detection by Zend_Locale (on a side note - it was happening on Internet Explorer 8 on Windows 7). To avoid this issue, I set the locale for all requests manually to en_US, since I don't have any other use for Zend_Locale in the application. I put the following lines in the bootstrap -

$locale = new Zend_Locale('en_US');
Zend_Registry::set('Zend_Locale', $locale);

As recommended by the manual to achieve this effect.

In my opinion, the Locale should be not be auto-detected by default - it should be an opt-in feature if it affects other components behind the scenes.

Fetching specific rows from a group with MySQL

Friday, March 12th, 2010

In a normalized database, we store separate entities in separate tables and define relationships between them, those being - one-to-one, one-to-many and many-to-many. We often want to fetch data which is split over two or more related tables, which is dead simple when fetching the extra data from the 'one' side of a relationship (ie, from a "parent" table):

SELECT product_images.src,products.name
FROM product_images
INNER JOIN products ON product_images.parent_id=products.id

Literally: Get the name of the parent product for each row in the products_images table.

Going the other direction is not as trivial. If we just want all the referenced rows in the child table, the query seen before would do the trick. But if we wanted a specific row to be found - for example, the latest inserted image, it becomes somewhat more complicated.
(more...)

Creating embedabble widgets

Friday, February 5th, 2010

Distribution of embeddable widgets is a common feature in many web services today. The most well known example is probably google's adsense that allows site owners to add google ads to their sites. Embeddable widgets allow a subset of functionality to be used on third-party sites, greatly increasing possible market reach for a web service / application.
(more...)

Back to business

Tuesday, January 26th, 2010

After a long hiatus, I'm getting back to blogging on web technologies, startups and other miscellanea. I've just completed a re-design of the site, which I'm proud to say I've done myself (with some finishing touches and advice from my two partners at Lionite).

I'm looking forward to expand discussion on some subjects I've brought up in the past (especially models in the Zend Framework) as well write on some of things we've been doing lately. Hope you will find it useful / interesting.

Client development – think partners, not employers

Thursday, July 30th, 2009

Saying there is a lot of variation in the field of web development would be a huge understatement. You have everything from anonymous freelancers to large known firms, several hundred dollar budgets to several hundred thousand dollar budgets (and more).

How much does it cost to build a website? what does building a website entails? there are no universal answers to those questions.

Client: "Enough talking, let's get down to business. What will 50$ get me?"
Brad: * looks at wrist watch *
Brad: "About 5 more minutes of my time."
Brad Colbow on Time

In fact, there is so much variation, that a recent client told us post-project completion that when he was shopping around for offers from various firms, he got offers between 2000$ and 60,000$. That's a factor of 30 between offers!

He picked us since we conveyed the best value (quality / price) of all offers, even though he had much cheaper offers (we were about midway in the range). All things being equal, all he had was his gut-feeling and our resume to guide him. That is, if we didn't engage in client development.
(more...)