Unexpected behavior with drop-down option order using minYear, maxYear in CakePHP

I noticed something interesting when testing a checkout form today build in CakePHP. The options for the drop-down were in descending order. The options were for the credit card expiration date field. The range was set with minYear and maxYear attributes.

The code in my view (CakePHP version 1.3.7).

echo $this->Form->input('cc_expires', array('type' => 'date',
  'label' => 'Expiration Date',
  'dateFormat' => 'MY',
  'empty' => true,
  'separator' => ' ',
  'minYear' => date('Y'),
  'maxYear' => date('Y', strtotime('+7 years')));

Although the options range is correct, this seemed unintuitive. In addition, I felt it was slightly poor usability. So I wanted to fix the order.

CakePHP default option order

CakePHP default option order

I dug around in The Book. Nothing. I was about to submit a ticket. But before I do, I typically check my version and the core. Upon searching for minYear I found the function in question – year(). Apparently an undocumented attribute exists – orderYear. After adding 'orderYear' => 'asc' to the options array I got the desired output.

Two notes here. First, CakePHP has many undocumented features. It never hurts to dig around the core. Second, the orderYear attribute is completely unnecessary in this case. In fact, it is only used for the *year* drop-down. It could be easily determined from comparing minYear and maxYear. In this case, minYear is 2012 which is less than maxYear is 2019. Display in ascending order.

Control option order using orderYear for year in CakePHP

CakePHP option order with orderYear

Maybe orderYear has uses. But today it wasted my time.

</rant>

WordPress Database Connection Error After Migration

I was migrating a WordPress database from Production to Staging the other day and received the dreaded "Error establishing a database connection" afterwards. I verified the database name, username, password, host, etc. Everything was correct. What the hell?

Then it hit me, we enabled multisite for this WordPress install. After looking under the hood, although WordPress could connect to the database, it didn’t find a matching entry for our staging URL. Apparently it still displays "Error establishing a database connection" message. A quick update to the records in the wp_blogs, wp_sites, and wp_options database tables resolved this.

Hope that helps someone. Check out my other post if you’re interested in setting up WordPress for multiple environments.

Facebook Places vs Foursquare

The other day my friend pointed out something I thought was quite interesting. I have since found myself sharing it with other people. First, a little back story. Facebook recently released the concept of Places. The ability to check-in to a location and update your Facebook profile. This appeals to users of the constantly increasing mobile market. However this concept is not novel. Foursquare had gained some traction with this concept over a year ago. Given, Foursquare was strictly for the mobile platform. So the key difference here is market audience.

So here’s what I found interesting. All of which are facts at the time of this post. You draw your own conclusions. The Facebook iPhone App has icons on the on the application home screen. One of the icons is for the new Places functionality. This icon is square. The icon is a graphical rendering of a map. The icon contains lines which intersect in a pattern. This pattern forms a four.

I don’t like the conclusions I am drawing from what I see here. This tells me a good idea is no longer enough. Most of us developers know that intellectual property really means shit. But now, it would seem, being first to market no longer matters either. Unfortunately, I already figured this out too with LastPlayed. What seems to matter now is how large the platform from which you shout. And, at the moment, Facebook has a much larger platform than Foursquare. In the end, the probability is in Facebook’s favor to beat out Foursquare. No matter if it was indeed Foursquare’s idea or if they were first. As an aspiring web and mobile application developer, it’s tough to see even at the highest level, it’s a chicken eat chicken world.

Electrosis

I don’t know what it is, but I somehow know electronic devices. I’m not talking about how to use them. Unfortunately, I can’t describe exactly what I mean by know. I find it similar to osmosis – the process of molecule transfer between objects. As such, I am calling this electrosis – the process by which energy transfers between electrical devices and us. Let me provide some examples.

I am a developer, so I am around computers most hours of the day. I can’t tell you how many times I have written some code, ran it, and got an error. I can say if I had a dollar every time, I’d be able to write a lot more blog posts. Now for the real question for all you developers. How many times do you know the error? I don’t mean you read the message or got the line number. I mean in the same instant you realized it didn’t work, you also knew the problem. Now most would immediately suggest that this is nothing more than experience. And I would agree that any good developer intimately knows their code. Yet, I am beginning to believe there is something more here. Why didn’t I know the error moments earlier, before I tried to run my code? Did the literally computer tell me the error once I ran the code?

Lets consider another example that removes experience. I often have my iPhone on silent (without sound or vibration). For meetings or in an effort not to be rude, I flip that little switch on the side. More often than not I have pulled my iPhone out of my pocket to find someone calling or that I just received a text. I’m not talking about a call I was expecting. This is a truly random call. How did I know that my phone was ringing? What triggered my reaction to reach into my pocket and check my iPhone at a near unconscious level?

I say the answer to these questions is electrosis. No one can disagree that these devices put off energy. Both the electrical device and the human body are sophisticated things. What if we have a sensitivity to the energy given off by one another. In doing so we created some kind of symbiosis. Is it really that crazy to think that those of us frequently around electrical devices have formed some kind of bond? To me it’s no different than adapting to your natural environment. We are in the Age of Technology. Technology driven to be more integrated, personalized, and usable. It’s not a great leap that these devices are becoming part of us.

Root Cause Analysis

So many people seem to forget a key component of problem solving – root cause analysis. How can a problem be solved if you don’t understand it? Nonetheless,
in our fast paced society, under the pressure of immediacy the just get it done mentality reigns. You see it wrapped in wire and covered with duct tape. You hear it in expressions. Treating the symptom, not the problem. Can’t see the forest for the trees. You notice it in behavior. Denial. Excuses.

This is backward to me. I have an analytic mind. It has taken me a while to channel my thought processes, and I am still dialing in. But over the years, it has helped me major in Computer Science and minor in Philosophy and Psychology. It compliments my current profession as a developer. Although exhausting at times, it is a great benefit.

Well armed I have become proficient at hunting down the root cause of problems. To me, root cause analysis is the most important step in solving a problem and an indicator of a good developer. So much energy is wasted when solutions are formed without this step. You are merely proposing something unproven and based on a limited understanding. Yes, maybe your solution works. But does it last? Did it just mask the problem? Did it create a new problem? Can this solution be applied to the same problem again? Did you just get lucky?

You don’t have to break out your lab coat and microscope. But invest a few extra minutes next time you are presented with a problem. I have found those few minutes pay dividends later. Either by saving time or adding experience, in the end it feels right.