CakePHP Shell Not Seeing MySQL with MAMP Pro MAC

MAMP is a great product. It makes using the MAMP stack on MAC very easy. I liked it so much I actually purchased MAMP Pro. Installing was a breeze, configuration is simple, and it is up and running in no time. However, for some reason, when I am trying to connect to MySQL from a CakePHP shell, the database connection cannot be found. Read more

Limit Data by User with CakePHP

CakePHPThrough the years, I have realized there are two types of web applications.

  • Community
  • Single User

While there are certainly some hybrid combination’s of these classifications, all applications can be categorized into these two categories. For example PHPNuke. It’s a single login to a community. As a user, you can use all of the functionality in the application AND you can see other users, etc. While something like FaceBook for example is a Hybrid of community and single user. While you can allow other users to see your data and content, they cannot modify your data or settings. You own that and nobody else has access to it without your username and password.

So comes the question. How can I limit data to a specific user with CakePHP? I love the CakePHP framework. But I have never been able to get a straight answer from anyone on the proper “cakeish” way to limit data to a specific user. For example. Let’s say I want to build a check book balancing application. I want it to be available to multiple subscribers. While all subscribers have access to the same functionality, they do not all see or modify the same data. While their data should be limited, they may all have access to the same Bank. This means that any user should be able to see all the banks we currently support… for example.

I have searched the internet and posted to stackoverflow.com trying to find the answer to this question. It is apparent that I am not the only one trying to figure this out. Add in the potential complexity to provide ADMIN routing and what you potentially have is a complicated mess of code if it is not done properly.

Well, search no more my Internet Friends! I think I have figured out the mess. I have been able to use a combination of things I have learned from here and here. But ultimately, I had to build this with good old ingenuity and a lot of trial and error. Keep Reading! Read more

Single Login For Multiple User Types with CakePHP

I started working on a project that requires a single login for multiple user types. Because of the way my mind organizes things, I was having difficulty getting my mind around multiple models pointing to the same table in the database. It just felt messy. But I found this to be the best solution. I can provide single user login and keep the user functionality separated.

In this case, I have managers and tenants both pointing to the users table. I simply add a ‘type’ column to the user table to track what type of user it is. Then in my callback methods on the models, I set the conditions for the beforeFind and the beforeSave within each model to it’s corresponding type. This keeps both the data it displays and the data it saves in check and accurate. Here is what my manager model looks like.

<?php
class Manager extends AppModel {

 var $name = 'Manager';
 var $useTable = 'users';

 // only return users where type = Manager
 function beforeFind($queryData) {
$queryData['conditions']['Manager.type'] = 'Manager';
return $queryData;
 }

 // Ensure the Type is set to Manager before saving this record
 function beforeSave() {
$this->data['Manager']['type'] = 'Manager';
return true;
 }

}

?>

The same would apply to the tenants model. This works like a charm. It helps to provide excellent separation between user types without writing a lot of extra code to manage and check for the differences in user types.

Happy coding!

Is the customer always right?

I have had some discussions with a project manager about how we use technology and the decision making process behind it. During one such discussion I raised issues with the choice of technologies for the development of some tools we were developing. The debate came to an abrupt end when he said, “The customer is always right.” This got me thinking. Is that true? Should it be that way? Read more

Open Source CakePHP Components

CakePHPI am getting more focused in my engineering career. Lately I have been feeling a strong desire to contribute to the open source community. Of course by open source community I mean contributing code and making it available to anyone who wants to use it… for free. As such, I decided to pick something I am passionate about. I have decided to create components, helpers, and other bits of code that are usable with the CakePHP framework. I have also decided to make these snippets of code available on GitHub. Read more

Job Interviews: Fair Question?

A few days ago I read a blog about job interviews. The way I found it was by glancing through a LinkedIn summary email I get frequently. The email contained a snippet about how to answer the question, “Why do you want to work here?” I followed the link to the blog, read the article, and watched the video as to how to respond. I must say, it’s a huge steamy crock of crap! Their response as to how to answer this question is similar to saying, “I have read your profile on FaceBook. I talked to other people who have dated you. I have read your blog. I want to marry you.” What!? Are you kidding me? Read more

Domain Validation Class Updated

Around three weeks ago, I sent an email to iana.org about their TLD file. (http://data.iana.org/TLD/tlds-alpha-by-domain.txt) This is the file that contains a list of all the valid top level domains (TLDs) on the Internet.  Here is a snippet from the email I sent requesting how to best access this file for my domains class: Read more

AJAX Loading Image Generation Web 2.0

Have you ever wanted to create an animated .gif for your Ajax enabled lightbox? Or any other Ajax/Processing screen where you want to give the user the impression something is actually happening in the background? Well, now you can and you barely have to life a finger! I found this new website that will not only allow you to pick the style, but you can also pick the colors; foreground and background! Just zip over to to http://ajaxload.info/ and get yours today!

Apple Introduces the iPad

So you have heard of the iMac, the iPod, the iPhone, and the iTouch. Well, Apple is at it yet again with the introduction of their newest hybrid of Mac and iTouch rolled into one. Introducing the new iPad! Shipping in March, this unit is supposed to have 3G technology (wireless anywhere) and will handle the latest apps from the app store. What’s more, is Apple has simultaneously released an SDK (Software Developers Kit) with it. This means we will be seeing new applications developed specifically for the iPad.

The iPad will be built with WiFi so it will make for a great media device around the house or office. Maybe even your favorite hot spot where WiFi is available. Since they are touting it as the “best way to experience the web, email, photos, and video. Hands down.”

Price starts at $499. It comes in 16GB, 32GB, and 64GB models. It also appears to have the ability to connect an external keyboard. Want to learn more, you can visit the Apple website to find out all the details.

Hidding Table Row While Preserving Colspan

Someone asked me today how to write the CSS for a <TR> so that the <TD colspan”2″> would still maintain the colspan when the display was changed from none to show. It turns out the solution is easier than you might think. He actually came up with the solution, but I took it a step further and updated it so include a toggle. Now you can repeatedly change the row from hidden to visible. Keep reading to see the solution. Read more