<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>BlogChuck</title>
	
	<link>http://blogchuck.com</link>
	<description>how much blog can blogchuck blog</description>
	<lastBuildDate>Sun, 29 Aug 2010 02:12:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/JustChuck" /><feedburner:info uri="justchuck" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Install SpamAssassin on Mac OSX 10.6</title>
		<link>http://feedproxy.google.com/~r/JustChuck/~3/Y15B9TjZSFw/</link>
		<comments>http://blogchuck.com/2010/08/install-spamassassin-on-mac-osx-10-6/#comments</comments>
		<pubDate>Sun, 29 Aug 2010 02:12:03 +0000</pubDate>
		<dc:creator>Chuck Burgess</dc:creator>
				<category><![CDATA[Musings]]></category>

		<guid isPermaLink="false">http://blogchuck.com/?p=363</guid>
		<description><![CDATA[I had an interesting conversation with a colleague of mine today. You see, we are working with a company that is going to do some marketing for us. The issue we are facing is their IT guy is a Microsoft kool-aide drinker. He knows just enough to get himself in trouble, but couldn&#8217;t code his [...]]]></description>
			<content:encoded><![CDATA[<p>I had an interesting conversation with a colleague of mine today. You see, we are working with a company that is going to do some marketing for us. The issue we are facing is their IT guy is a Microsoft kool-aide drinker. He knows just enough to get himself in trouble, but couldn&#8217;t code his way out of a paper bag. But we have to work through him to get any email sent. We are being blocked because he looks at the content we want to send and says, &#8220;There is not enough content, it will be marked as spam. We need more content.&#8221;</p>
<p>Someone please correct me if I am wrong, but spam filtering does not necessarily only look at the quantity of the content, but the quality and specific words the contained within it. For example, spamassassin uses filtering that will check the content and apply a score based on multiple things like: relays, headers, subject line, dates, etc. So the first question I asked was, &#8220;How can this Microsoft loving IT guy eyeball the content and be able to tell it will be marked as spam?&#8221;</p>
<p><span id="more-363"></span>Clearly he cannot. But because he is the resident geek at this organization, he is in control. This led me to realize, I need to get hard data. In order to combat his nonsensical approach to spam checking (by using his eyeballs), I figured I need something a little more concrete. So I set out to install SpamAssassin on my MacBookPro. Would it work? I didn&#8217;t know but I had to try. Not only because I needed something to run spam scores against, but it sounded challenging and fun at the same time.</p>
<p><strong>Easy? So it seems</strong></p>
<p>I did some searching on the web, and there was not a lot about HOW to get it installed on a Mac. So I did a little more digging and came across an article written in back in 2007 that lead me down the right path. My Linux knowledge started ti kick in again and before you know it, I am in business. I now have spamd (and spamc) running on my Mac. Here is what I did.</p>
<p><strong>The Install</strong></p>
<p>First, you need a handful of perl modules to meet the dependencies for Mail::SpamAssassin. I used the following command from the terminal:</p>
<blockquote><p>perl -MCPAN -e shell</p></blockquote>
<p>This brought up the<em> cpan&gt;</em> prompt. I tried running <strong><em>install Mail::SpamAssassin</em></strong> which failed because of the dependencies. But I paid attention to the output and pulled down the list and installed the dependencies one by one from the span shell.</p>
<blockquote><p>NetAddr::IP<br />
Mail::SPF<br />
IP::Country<br />
Razor2<br />
Net::Ident<br />
Mail::DKIM<br />
Encode::Detect</p></blockquote>
<p>A few things to note. First, Razors2 is not found in cpan. I have to <a title="Razor2" href="http://sourceforge.net/projects/razor/files/razor-agents/2.84/razor-agents-2.84.tar.bz2/download" target="_blank">download</a> it from sourceforge and install it by hand. Once I downloaded it, I uncompressed it, went to the uncompressed directory in terminal, and ran the following:</p>
<blockquote><p>perl Makefile.PL &amp;&amp; make</p>
<p>sudo make install</p></blockquote>
<p>Second, once all of the dependencies were installed, I then ran the install for SpamAssassin from the cpan shell:</p>
<blockquote><p>install Mail::SpamAssassin</p></blockquote>
<p>The problem is, I got some errors. I did what came natural to me and decided to go into the actual directory ~/.cpan/build/{spamassassin} and run the same perl Makefile&#8230; commands. Wouldn&#8217;t you know it worked?</p>
<p><strong>Did It Really Work?</strong></p>
<p>What do you know, from the same terminal I ran <strong><em>spamd &amp; </em></strong>and guess what? SpamAssassin is running on my Mac! I now have the ability to test spam scores for email messages. So now, on the command line I can run:</p>
<blockquote><p>spamc -R &lt; <em>{emailfile}</em></p></blockquote>
<p>Now all I need to do is write my custom PHP script to pass email files to spamc via the exec() and I am good to go. In the meantime, I plan on combating evil Microsoft fanboy by showing him sctual spam scores to compare with his eyeball by running them manually in my terminal. Question is, will be pull a Microsoft and try to change the standard from spam score to evil eyeball of said IT fanboy? We will soon find out.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/8qCuuVqgREolmohkVh9EG1y8GcA/0/da"><img src="http://feedads.g.doubleclick.net/~a/8qCuuVqgREolmohkVh9EG1y8GcA/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/8qCuuVqgREolmohkVh9EG1y8GcA/1/da"><img src="http://feedads.g.doubleclick.net/~a/8qCuuVqgREolmohkVh9EG1y8GcA/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://blogchuck.com/2010/08/install-spamassassin-on-mac-osx-10-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blogchuck.com/2010/08/install-spamassassin-on-mac-osx-10-6/</feedburner:origLink></item>
		<item>
		<title>How To Treat A Coder (a Geek)</title>
		<link>http://feedproxy.google.com/~r/JustChuck/~3/gRPBkRlQGs0/</link>
		<comments>http://blogchuck.com/2010/08/how-to-treat-a-coder-a-geek/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 03:52:17 +0000</pubDate>
		<dc:creator>Chuck Burgess</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[Musings]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blogchuck.com/?p=356</guid>
		<description><![CDATA[I have been thinking a lot lately about what it means to write code. What is a coder exactly? I have asked myself the question, &#8220;Why are there some companies who understand how to treat coders, and others who do not?&#8221; A coder is someone who can speak to a computer through text. The computer [...]]]></description>
			<content:encoded><![CDATA[<p>I have been thinking a lot lately about what it means to write code. What is a coder exactly? I have asked myself the question, &#8220;Why are there some companies who understand how to treat coders, and others who do not?&#8221;</p>
<p><span id="more-356"></span>A coder is someone who can speak to a computer through text. The computer understands what the coder is saying and will perform specific tasks as outlined. Think of it as any foreign language with one caveat. The language of computers is typed not spoken. In addition, it must be spoken flawlessly, or the computer will not understand.</p>
<p>When I think of a coder (also called a developer or programmer), I think of a journalist. Day in and day out, coders write content. This content is translated into some form of application, but it is still written.</p>
<p>Coders do not produce widgets on an assembly line. But they write the software that automates the robots that produce the widgets. They write the software that runs the packaging machinery for the widgets. They write the software that labels, ships, and tracks the packages the widgets are sent in.</p>
<p>When I thought about coders in this way, I came to a stark realization. I finally understood what made the difference between a &#8220;coder friendly&#8221; company and one that is not. Allow me to explain.</p>
<p><strong>Technical vs. Non-Technical</strong></p>
<p>We first must understand the differences between a technical and a non-technical company as they relate to coders. I will use easy straight forward comparisons to show what I mean. Take <a title="Google" href="http://www.google.com" target="_blank">Google</a> or <a title="Yahoo!" href="http://www.yahoo.com" target="_blank">Yahoo</a> for example. Both are technical companies. The primary focus of their company revolves around code. You can put other companies into this same category like <a title="Digg" href="http://www.digg.com" target="_blank">Digg</a>, <a title="Facebook" href="http://www.facebook.com" target="_blank">Facebook</a>, <a title="ebay" href="http://www.ebay.com" target="_blank">ebay</a>, and the list goes on. While one could say the focus of these companies is not technology, the fact remains that without the technology, these companies would not exist.</p>
<p>A non-technical company my use technology, but their primary business it not necessarily the technology. It merely uses technology to promote their business. Take <a title="ESPN" href="http://www.espn.com" target="_blank">ESPN</a> for example. They have a very large presence on the Internet and use lots of great technology, but their primary business is Sports. However, if the internet were to disappear tomorrow, ESPN would still continue broadcasting and putting out their sports magazine.</p>
<p><strong>Industrial Age vs Information Age</strong></p>
<p>If we think back to the industrial age, how were things produced? That&#8217;s right. An assembly line. The old manufacturing plant. Quoting from one <a title="Manufacturing Methodology" href="http://businessmanagement.suite101.com/article.cfm/manufacturing_methodology_influencing_factors" target="_blank">manufacturing methodology</a>:</p>
<blockquote><p><em>Manufacturing involves transforming raw materials into finished products. These products might be consumer or industrial products, or intermediate products used in further manufacture to produce consumer or industrial products. Manufacturing started as handicrafts by skilled craftsmen and has now become mainly a capital intensive activity that uses plant and machinery.</em></p></blockquote>
<p>So for centuries, all of our business schools have been teaching MBAs and managers how to manage within a manufacturing setting. Raw materials in, product out. The non-technical managers try to manage coders like they are on an assembly line. This was it! The reason behind the disconnect! Non technical managers do NOT understand how to work with and treat coders. Yet companies persist in putting them in charge of the coders.</p>
<p><strong>Path to Utpoia</strong></p>
<p>Coders are a unique breed of individual.  Most are completely happy to sit behind a flickering screen for 8-16 hours a day writing code. That is, until they feel like they are not appreciated. Most companies don&#8217;t care. They treat their employees much like manufacturing plants treat machinery. Work it to death with very little maintenance. When it breaks down, try to fix it. If it cannot be fixed, replace it. What these companies need to realize is, coders are NOT machinery.</p>
<p>A company who puts a technical manager in charge and offers great benefits (insurance and otherwise) to their coders is the place to work if you are looking for a salaried position. Anywhere else will be miserable. As soon as companies start to realize this, they will reduce turn over and begin to build a stronger company. This is why coders flock to companies like Google. They know how to treat the coders.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/eaBtd888NISOT-73JihXYbR5AbM/0/da"><img src="http://feedads.g.doubleclick.net/~a/eaBtd888NISOT-73JihXYbR5AbM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/eaBtd888NISOT-73JihXYbR5AbM/1/da"><img src="http://feedads.g.doubleclick.net/~a/eaBtd888NISOT-73JihXYbR5AbM/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://blogchuck.com/2010/08/how-to-treat-a-coder-a-geek/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blogchuck.com/2010/08/how-to-treat-a-coder-a-geek/</feedburner:origLink></item>
		<item>
		<title>CakePHP Shell Not Seeing MySQL with MAMP Pro MAC</title>
		<link>http://feedproxy.google.com/~r/JustChuck/~3/ghvACbpO81o/</link>
		<comments>http://blogchuck.com/2010/07/cakephp-shell-not-seeing-mysql-with-mamp-pro-mac/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 15:55:17 +0000</pubDate>
		<dc:creator>Chuck Burgess</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://blogchuck.com/?p=344</guid>
		<description><![CDATA[Connecting to MySQL on MAC with MAMP and CakePHP shells.]]></description>
			<content:encoded><![CDATA[<p>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.<span id="more-344"></span></p>
<p>The error I was getting was:</p>
<p><strong><em>Warning: mysql_connect(): [2002] No such file or directory (trying to<br />
connect via unix:///tmp/mysql.sock) in /Users/myuser/Sites/cakephp/cake/libs/model/datasources/dbo/dbo_mysql.php<br />
on line 540</em></strong></p>
<p>So I had to figure out what the issue was and resolve it. The solution was very simple. The error gives a clue. It turns out that CakePHP is looking for the mysql socket in <em>/tmp</em>. However, MAMP is running the socket in <em>/Applications/MAMP/tmp</em>. We just have to symbolically link the socket that CakePHP is looking for to the actual socket MySQL is running on in MAMP. This can be accomplished with the following command after MAMP Pro is running:</p>
<pre class="brush: sql;">
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
</pre>
<p>This will resolve the issue and MAMP will run as expected for CakePHP shell applications. I hope this helps.</p>
<p>Happy Coding!</p>

<p><a href="http://feedads.g.doubleclick.net/~a/3GjbjGWs_P6LPRp34casQ5jR4Lw/0/da"><img src="http://feedads.g.doubleclick.net/~a/3GjbjGWs_P6LPRp34casQ5jR4Lw/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/3GjbjGWs_P6LPRp34casQ5jR4Lw/1/da"><img src="http://feedads.g.doubleclick.net/~a/3GjbjGWs_P6LPRp34casQ5jR4Lw/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://blogchuck.com/2010/07/cakephp-shell-not-seeing-mysql-with-mamp-pro-mac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blogchuck.com/2010/07/cakephp-shell-not-seeing-mysql-with-mamp-pro-mac/</feedburner:origLink></item>
		<item>
		<title>Limit Data by User with CakePHP</title>
		<link>http://feedproxy.google.com/~r/JustChuck/~3/jMzDsvjGF94/</link>
		<comments>http://blogchuck.com/2010/06/limit-data-by-user-with-cakephp/#comments</comments>
		<pubDate>Sat, 19 Jun 2010 00:03:03 +0000</pubDate>
		<dc:creator>Chuck Burgess</dc:creator>
				<category><![CDATA[Musings]]></category>

		<guid isPermaLink="false">http://blogchuck.com/?p=331</guid>
		<description><![CDATA[How to limit data to a specific user in CakePHP]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-thumbnail wp-image-313" title="cake-logo" src="http://blogchuck.com/wp-content/uploads/2010/03/cake-logo-150x150.jpg" alt="CakePHP" width="150" height="150" />Through the years, I have realized there are two types of web applications.</p>
<ul>
<li>Community</li>
<li>Single User</li>
</ul>
<p>While there are certainly some hybrid combination&#8217;s of these classifications, all applications can be categorized into these two categories. For example PHPNuke. It&#8217;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.</p>
<p>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 &#8220;cakeish&#8221; way to limit data to a specific user. For example. Let&#8217;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&#8230; for example.</p>
<p>I have searched the internet and posted to <a title="StackOverflow.com" href="http://stackoverflow.com/questions/3030209/how-to-limit-data-to-users-who-own-it-without-limiting-admin-users-in-cakephp" target="_blank">stackoverflow.com</a> 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.</p>
<p>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 <a title="Teknoid" href="http://teknoid.wordpress.com/2009/01/12/462/" target="_blank">here</a> and <a title="StudioCanaria" href="http://www.studiocanaria.com/articles/cakephp_auth_component_users_groups_permissions_revisited" target="_blank">here</a>. But ultimately, I had to build this with good old ingenuity and a lot of trial and error. Keep Reading!<span id="more-331"></span></p>
<p><strong>The Code</strong></p>
<p>To start out with, there has to be a way to determine if the user is an ADMIN or just a standard USER. This will require that we put a &#8216;roll&#8217; field in the users table. Here is what my table looks like.</p>
<pre class="brush: sql;">
--
-- Table structure for table `users`
--

CREATE TABLE `users` (
`id` char(36) NOT NULL,
`username` varchar(255) NOT NULL,
`password` varchar(40) NOT NULL,
`first_name` varchar(35) NOT NULL,
`last_name` varchar(35) NOT NULL,
`role` enum('admin','user') NOT NULL DEFAULT 'user',
`active` tinyint(4) NOT NULL DEFAULT '0',
`created` datetime NOT NULL,
`modified` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
</pre>
<p>There is nothing really new about this table. It&#8217;s fairly straight forward and a typical users table. I use an email address for the username.</p>
<p>Now, the thing to keep in mind is I want to limit all of the data a USER sees to her own data while allowing any global data. This means there are a few checks that must occur each time the user accesses the site. Now for the &#8220;magic&#8221; piece that will accomplish this.</p>
<pre class="brush: php;">
&lt;?php
class AppController extends Controller {
beforeFilter() {
 if ($this-&gt;isAdmin()) {
     $this-&gt;beforeAdminFilter();
 } else {
     $this-&gt;beforeUserFilter();
 }
}

function beforeAdminFilter() {
 if ($this-&gt;Auth-&gt;user('role') !== 'admin') {
   $this-&gt;Session-&gt;setFlash(sprintf(__('%s is not authorized!', true), 'User'));
   $this-&gt;redirect('/users');
 }
}

 function beforeUserFilter() {
   Configure::write('user_id', $this-&gt;Session-&gt;read('Auth.User.id'));
 }

 function isAdmin() {
   return (isset($this-&gt;params['admin']) &amp;&amp; $this-&gt;params['admin']) ? true : false;
 }
}
</pre>
<p>A few things I need to point out here. I use the <a title="StudioCanaria" href="http://www.studiocanaria.com/articles/cakephp_auth_component_users_groups_permissions_revisited" target="_blank">StudioCanaria</a> method for ACL. This is a great solution in my opinion. But I am not showing all of the code for that solution. It would make it more obscure and difficult to understand. This is just the vanilla portions I added in for my &#8220;limiting data&#8221; purposes.</p>
<p>Now for the more complicated part.</p>
<pre class="brush: php;">
&lt;?php
class AppModel extends Model {
 var $user_id;

function beforeFind($queryData) {
  if($this-&gt;user_id = Configure::read('user_id')){  // must be a user (not admin)
   if(isset($this-&gt;_schema['user_id'])) {
    if(isset($this-&gt;user_id)) {
     $queryData['conditions'][$this-&gt;name.'.user_id'] = $this-&gt;user_id;
    }
   }
   if($this-&gt;name == 'User') {
    $queryData['conditions'][$this-&gt;name.'.id'] = $this-&gt;user_id;
   }
  }
  return $queryData;
}

function beforeSave() {
 if($this-&gt;user_id = Configure::read('user_id')){    // must be a user (not admin)
  if(isset($this-&gt;_schema['user_id'])) {
   $this-&gt;data[$this-&gt;name]['user_id'] = $this-&gt;user_id;
  }
 }
 return true;
}

}
?&gt;
</pre>
<p>Isn&#8217;t this how it is suppose to be? The heaviest part of the code should be in the models? Well this is the part that does the heavy lifting. Basically this will restrict anything that is associated to a USER. Ok, let&#8217;s dive in and I will explain how it works.</p>
<p><strong>beforeFind</strong></p>
<p>This is the function that is called before any search is done on the data. Now, keep in mind the two caveats to this configuration. 1- Not all data is associated to a USER and 2) ADMIN users are not limited. With that in mind, let&#8217;s analyze this code.</p>
<pre class="brush: php;">
if($this-&gt;user_id = Configure::read('user_id')){  // must be a user (not admin)
</pre>
<p>This line establishes that we are in fact dealing with a USER. Notice I am using a &#8220;global variable&#8221;? This is so I can easily pass the data back and forth between the APP_CONTROLLER and MODEL_CONTROLLER.</p>
<p>Now comes the first part of the magic. Does this schema (Model) require a user_id field?</p>
<pre class="brush: php;">
if(isset($this-&gt;_schema['user_id'])) {
</pre>
<p>This will determine if we need to actually &#8220;limit&#8221; the data. It will prevent the user from seeing anything accept the users data. How? Because if we detect a USER_ID, we set the condition to limit the data by the current user_id of the user looking at the data.</p>
<pre class="brush: php;">
$queryData['conditions'][$this-&gt;name.'.user_id'] = $this-&gt;user_id;
</pre>
<p>The line before it is just because I am paranoid about my code breaking. So feel free to flame me about this:</p>
<pre>if(isset($this-&gt;user_id)) {</pre>
<p>But I will still leave it in. If you are comfortable taking it out, feel free. So there you have it. You are now limiting your $this-&gt;{MODEL}-&gt;find queries to a specific user. You will note that for the USER model, the user id is actually ID so I account for that in the next few lines. It is also important to note I use the standard foreign-key ID configuration common to good SQL practices. Any table associated to a user has the USER_ID as the foreign-key. I wont go into the horror stories of some of the things I have seen. (Including some of the work I have seen at Yahoo! while I have been consulting there.)</p>
<p>One more thing. If you have a beforeFilter in your model, it will override your app_model.beforeFilter. so you need to add the following:</p>
<pre class="brush: php;">
&lt;?php
class YourModel extends Model {
   // your code

  function beforeFilter(){
    parent::beforeFilter();  // &lt;==== this is the important part
    // your filter code here
  }

  // your code
}
?&gt;
</pre>
<p>Let&#8217;s continue.</p>
<p><strong>beforeSave</strong></p>
<p>This function is basically the same thing. However, as you may have guessed, it is to prevent a user from saving over another users data by chance they were able to randomly guess the ID.</p>
<p><strong>Conclusion</strong></p>
<p>There you have it! The only &#8220;user control&#8221; process for CakePHP that exists on the entire internet, at least that I am aware of. If you happen to know of another one that is more elegant, or you have a way to better improve this one, please drop a note in the comments. I find that many times I tend to overlook even some of the more simple solutions.</p>
<p>Happy Coding!</p>

<p><a href="http://feedads.g.doubleclick.net/~a/19AzLKOalg6LuiB_MifS9G5Z1gA/0/da"><img src="http://feedads.g.doubleclick.net/~a/19AzLKOalg6LuiB_MifS9G5Z1gA/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/19AzLKOalg6LuiB_MifS9G5Z1gA/1/da"><img src="http://feedads.g.doubleclick.net/~a/19AzLKOalg6LuiB_MifS9G5Z1gA/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://blogchuck.com/2010/06/limit-data-by-user-with-cakephp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blogchuck.com/2010/06/limit-data-by-user-with-cakephp/</feedburner:origLink></item>
		<item>
		<title>Single Login For Multiple User Types with CakePHP</title>
		<link>http://feedproxy.google.com/~r/JustChuck/~3/rZhRKImgbqc/</link>
		<comments>http://blogchuck.com/2010/04/single-login-for-multiple-user-types-with-cakephp/#comments</comments>
		<pubDate>Wed, 28 Apr 2010 13:11:07 +0000</pubDate>
		<dc:creator>Chuck Burgess</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blogchuck.com/?p=326</guid>
		<description><![CDATA[Limit models to a specific subset of data using multiple models pointing to the same table.]]></description>
			<content:encoded><![CDATA[<p>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.</p>
<p>In this case, I have managers and tenants both pointing to the users table. I simply add a &#8216;type&#8217; 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&#8217;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.</p>
<pre class="brush: php;">
&lt;?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-&gt;data['Manager']['type'] = 'Manager';
return true;
 }

}

?&gt;
</pre>
<p>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.</p>
<p>Happy coding!</p>

<p><a href="http://feedads.g.doubleclick.net/~a/-8E7mCkUQDJIs_mZ3i3APKcRh3E/0/da"><img src="http://feedads.g.doubleclick.net/~a/-8E7mCkUQDJIs_mZ3i3APKcRh3E/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/-8E7mCkUQDJIs_mZ3i3APKcRh3E/1/da"><img src="http://feedads.g.doubleclick.net/~a/-8E7mCkUQDJIs_mZ3i3APKcRh3E/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://blogchuck.com/2010/04/single-login-for-multiple-user-types-with-cakephp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blogchuck.com/2010/04/single-login-for-multiple-user-types-with-cakephp/</feedburner:origLink></item>
		<item>
		<title>Is the customer always right?</title>
		<link>http://feedproxy.google.com/~r/JustChuck/~3/wSGlGADf9mM/</link>
		<comments>http://blogchuck.com/2010/03/is-the-customer-always-right/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 15:38:54 +0000</pubDate>
		<dc:creator>Chuck Burgess</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Ranting]]></category>

		<guid isPermaLink="false">http://blogchuck.com/?p=321</guid>
		<description><![CDATA[How do you bridge the gap between the customer (who doesn't know) and the developer (who should)?]]></description>
			<content:encoded><![CDATA[<p>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, &#8220;The customer is always right.&#8221; This got me thinking. Is that true? Should it be that way? <span id="more-321"></span>After we hung up the phone, I began doing research as to why the choice of technology was bad and why my suggestion was better. But I kept coming back to his statement, &#8220;The customer is always right.&#8221; How would I explain that this should NOT be held as a truth? In this case, I can&#8217;t. It will fall on deaf ears. However, I can still point out why that should NOT be used as a reason to do something &#8220;wrong&#8221; because the customer said so.</p>
<p>While reading an article at <a href="http://www.phparch.com/2010/03/10/programming-youre-doing-it-wrong/" target="_blank">PHP|Architect</a>, the author (<a href="http://twitter.com/mtabini" target="_blank">Marco Tabini</a>) said, &#8220;we’re moving from fad to fad without stopping to consider that  technology is a <em>tool</em> and not a substitute for our own  responsibility to make choices.&#8221; Yet when you take the path of &#8220;the customer is always right,&#8221; you remove from the equation what I consider part of your responsibility as the expert; the reason you were hired in the first place.</p>
<p>Allow me to provide an example for clarity. You are hired to build a website by Company Y. The business owner (the person you work for) say, &#8220;Chuck, I am a big fan of Cobol. I learned it in my college days. I can&#8217;t remember much about it except that there are 4 function areas or something like that, and it is good at crunching numbers. So your task is to build me a website that will crunch my analytics data and I want it done in Cobol. Go!&#8221;</p>
<p>What?! So is the customer right? Or do I have an obligation to explain why this is a bad thing? Where does the business owners request end and my obligation begin? Anyone in the computer industry today could say multiple things to this request like:</p>
<ul>
<li>it&#8217;s impossible</li>
<li>not gonna happen</li>
<li>this is a very bad idea</li>
<li>I quit</li>
</ul>
<p>But I cannot fathom anyone saying, &#8220;The customer is always right!&#8221; So what is the alternative?</p>
<p><strong>My Perspective</strong></p>
<p>I think the perspective &#8220;the customer is always right&#8221; does have some merit. But this does not mean the customer is God. Here is a better way to state it, &#8220;You can ask for WHAT you want, and I will tell you HOW you will get it.&#8221; This can sound a bit abrasive as it is so I will clarify.</p>
<p>No developer can go into a situation and pretend to know what the requirements of a project is without first talking about them with the customer. (The WHAT) Once a fair assessment of the situation is made, the developer SHOULD then be able to formulate the HOW to fulfill the requirements. When the customer defines the WHAT and the HOW, it&#8217;s akin to a Judge overseeing the trial of her brother who is being accused of murder. A HUGE conflict of interest to say the least. The customer (like the judge) should recuse themselves from the decision making process.</p>
<p>To help the customer recuse themselves, you need to be able to explain the WHY of the situation. Granted, most of us geeks tend to be social misfits and have difficulty explaining technology in &#8220;layman&#8221; terms. So it typically comes out something like, &#8220;Are you kidding? Cobol went out with New Coke and the TRS-80. It won&#8217;t support HTML, AJAX, or SQL. There are no existing APIs, so XML, JSON, and RESTful services are out. Not to mention it cannot use HTTP protocol and it wont send email whether it&#8217;s POP, IMAP, or otherwise. So why do you want to use Cobol?&#8221;</p>
<p>The customer will then do one of two things: 1- stare at you with glossy eyes as if he just visited a far away place on a very wonderful day dream -or- 2- do the unthinkable and say, &#8220;Make it happen!&#8221;</p>
<p><strong>The Dichotomy</strong></p>
<p>There seems to be dichotomy between the developer and the customer. This gap as it were, does not seem to be narrowing much. The average customer has no real desire to walk up to the edge of the technological precipice and peer in, and the developer usually lacks the skill to communicate things to those &#8220;not in the know&#8221; in an understandable way.</p>
<p>What can be learned from all of this? No! The customer is NOT always right. But it is the responsibility and obligation of the developer to say why in a way that the customer will understand. What do you think?</p>

<p><a href="http://feedads.g.doubleclick.net/~a/19ZjGlg4C9T-iNHtkTs6payl0yE/0/da"><img src="http://feedads.g.doubleclick.net/~a/19ZjGlg4C9T-iNHtkTs6payl0yE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/19ZjGlg4C9T-iNHtkTs6payl0yE/1/da"><img src="http://feedads.g.doubleclick.net/~a/19ZjGlg4C9T-iNHtkTs6payl0yE/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://blogchuck.com/2010/03/is-the-customer-always-right/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blogchuck.com/2010/03/is-the-customer-always-right/</feedburner:origLink></item>
		<item>
		<title>Open Source CakePHP Components</title>
		<link>http://feedproxy.google.com/~r/JustChuck/~3/mblka0MAB0Y/</link>
		<comments>http://blogchuck.com/2010/03/open-source-cakephp-components/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 17:58:46 +0000</pubDate>
		<dc:creator>Chuck Burgess</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blogchuck.com/?p=311</guid>
		<description><![CDATA[Open source CakePHP components.]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-thumbnail wp-image-313" title="cake-logo" src="http://blogchuck.com/wp-content/uploads/2010/03/cake-logo-150x150.jpg" alt="CakePHP" width="114" height="114" />I 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&#8230; 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.<span id="more-311"></span></p>
<p>Some of the code components I have released include:</p>
<ul>
<li>Domain Validation</li>
<li>Email Validation</li>
<li>Google Maps Address Geo Coordinates</li>
</ul>
<p>I have also releases a simple GoogleMaps helper that will generate a self contained DIV with a GoogleMap v3 in it based on a series of points you pass.</p>
<p>I am still working on the documentation, but the code is freely available on my GitHub at:</p>
<p><a title="http://github.com/cdburgess/" href="http://github.com/cdburgess/">http://github.com/cdburgess/</a></p>
<p>I will write more about each component in later posts. However, you will note that the Domain and Email validation components are CakePHP component implementations of the Domain and Email validation classes I have released on Google Code.</p>
<p>Happy Coding!</p>

<p><a href="http://feedads.g.doubleclick.net/~a/ger7WBMaJedA7aFYXz5lphi1GcA/0/da"><img src="http://feedads.g.doubleclick.net/~a/ger7WBMaJedA7aFYXz5lphi1GcA/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ger7WBMaJedA7aFYXz5lphi1GcA/1/da"><img src="http://feedads.g.doubleclick.net/~a/ger7WBMaJedA7aFYXz5lphi1GcA/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://blogchuck.com/2010/03/open-source-cakephp-components/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blogchuck.com/2010/03/open-source-cakephp-components/</feedburner:origLink></item>
		<item>
		<title>Job Interviews: Fair Question?</title>
		<link>http://feedproxy.google.com/~r/JustChuck/~3/G67bZ0wtTgs/</link>
		<comments>http://blogchuck.com/2010/02/job-interviews-fair-question/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 22:24:38 +0000</pubDate>
		<dc:creator>Chuck Burgess</dc:creator>
				<category><![CDATA[Musings]]></category>

		<guid isPermaLink="false">http://blogchuck.com/?p=306</guid>
		<description><![CDATA[Why do you want to work here?... I need the money! What response were you expecting?]]></description>
			<content:encoded><![CDATA[<p>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, &#8220;Why do you want to work here?&#8221; I followed the link to the blog, read the article, and watched the video as to how to respond. I must say, it&#8217;s a huge steamy crock of crap! Their response as to how to answer this question is similar to saying, &#8220;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.&#8221; What!? Are you kidding me?<span id="more-306"></span></p>
<p>First, the company you are interviewing with is unknown. Sure, you may hear a lot about it on the Internet or word of mouth. But how do you really know you want to work there? Fact is, you don&#8217;t? And if you do, then it&#8217;s because you are interested in getting a job there and you were going to do your due diligence anyway. For example, an engineer may want to work for Google because their reputation precedes them. But who wants to work for SimpleNet Consulting? For me to say, &#8220;You don&#8217;t know anything about my company, why should I hire you&#8221; is quite arrogant.</p>
<p>So here is my response on how to answer the question, &#8220;Why do you want to work here?&#8221;And this is the comment I posted on the blog. Take it for what is is worth. But in my 40 years experience, I have rarely been asked this question. Maybe it&#8217;s because I am an engineer geek and they feel lucky just to get any social response that is coherent.</p>
<p>Interviewer: &#8220;Why do you want to work here?&#8221;</p>
<p>Me: &#8220;I&#8217;m not certain that I do. I know what your company does, but I am not familiar with the culture or the people. I may not be a good fit. I am qualified for the position and I am a perfect fit for what you are looking for. So let&#8217;s run a trial. Let&#8217;s hold hands before we kiss. You can give me a small project to work on. After 90 days if I have proven myself and you want to make it permanent we can. If I don&#8217;t fit into your culture or see things the way you would like, you let me go, no hard feelings.&#8221;</p>
<p>Having been on the other side of the table, I would admire the candor in this response. Confident but not cocky. Someone who at least sounds capable of doing the job and willing to prove it.</p>
<p>Besides, in my opinion, it is the job of the hiring company to articulate the qualifications of the candidate. It is not the responsibility of the candidate to understand what the company is looking for by reading about them on the Internet. Maybe I should write an article about appropriate Interview questions or how to publish job opportunities. After all, what is an interviewer trying to accomplish by asking why someone would want to work there? Are they stroking their ego or trying to discern what is really being said about them on the internet? Either way, it&#8217;s not a valid question in an interview. It speaks nothing to the qualifications of the candidate. Unless of course, you are looking for a CEO.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/mpvN2qjWWcs7NCX9dm1F14EAV7g/0/da"><img src="http://feedads.g.doubleclick.net/~a/mpvN2qjWWcs7NCX9dm1F14EAV7g/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/mpvN2qjWWcs7NCX9dm1F14EAV7g/1/da"><img src="http://feedads.g.doubleclick.net/~a/mpvN2qjWWcs7NCX9dm1F14EAV7g/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://blogchuck.com/2010/02/job-interviews-fair-question/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blogchuck.com/2010/02/job-interviews-fair-question/</feedburner:origLink></item>
		<item>
		<title>Domain Validation Class Updated</title>
		<link>http://feedproxy.google.com/~r/JustChuck/~3/faLMEfaC-aY/</link>
		<comments>http://blogchuck.com/2010/02/domain-validation-class-updated/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 07:58:47 +0000</pubDate>
		<dc:creator>Chuck Burgess</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP code]]></category>

		<guid isPermaLink="false">http://blogchuck.com/?p=301</guid>
		<description><![CDATA[New update to the Domain Validation Class provides automated TLD file updates from iana.org.]]></description>
			<content:encoded><![CDATA[<p>Around three weeks ago, I sent an email to iana.org about their TLD file. (<a href="http://data.iana.org/TLD/tlds-alpha-by-domain.txt" target="_blank">http://data.iana.org/TLD/tlds-alpha-by-domain.txt</a>) 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:<span id="more-301"></span></p>
<blockquote><p>I would like to access this file directly from my script, but I do not want to over burden your server as I am not certain how much  traffic this tool will get. I also want to release it to open source which could increase the traffic exponentially. However, I would like to automate the retrieval of the information so that we ensure we have the most up-to-date data available for validations the TLDs of domains. Do you have any suggestions?</p></blockquote>
<p>Well I am quite pleased with the response I got back. Kim Davies sent the following response:</p>
<blockquote><p>It is OK to query this page directly, that is its purpose.</p>
<p>The access pattern you wish to use will depend on how important the file  is up to date. Please bear in mind the list of TLDs changes, perhaps at most,  once a year at this time. For most applications retrieving a new copy every few  months is more than adequate. (Usually when a new TLD is launched, it is  piloted with no registrations for several months, so this should not cause a  problem.)</p>
<p>The absolute most you should fetch the file is twice a day, as it will  never change more often than that. We only make changes to the DNS root zone  twice a day.</p>
<p>We would also recommend you use &#8220;If-Modified-Since&#8221; headers when  retrieving the file so that if it has not changed you don&#8217;t retrieve the whole  file.</p></blockquote>
<p>So based on her feedback, this is what I did. I added a TLD file status check method to the domains class. This will provide the following functionality:</p>
<ul>
<li>checks to see if the file exists</li>
<li>checks to see how old the file on the server is</li>
<li>if the file does not exist or is more than 30 days old, it will download a fresh copy</li>
</ul>
<p>This will provide complete automation for the domains class. As long as the file exists, no matter how old it is, it will allow the domain name to be validated. The validation will NOT be interrupted even if the iana.org domain returns a 404 (not found). Unless of course you don&#8217;t have any TLD file at all.</p>
<p>The code can be downloaded from the repository. You can read more information about it&#8217;s functionality here:  <a href="http://code.google.com/p/blogchuck/wiki/DomainsClass" target="_blank">http://code.google.com/p/blogchuck/wiki/DomainsClass</a></p>
<p>I hope you find it useful. Feel free to comment or send me an email if you have any questions. I will continue to update the code. The key is to keep things as simple as possible while still being useful. Good clean code is easier to use than something just hacked together. I hope I have achieved the prior.</p>
<p>Happy coding!</p>

<p><a href="http://feedads.g.doubleclick.net/~a/pAecAOldIFX4wNyfEKG8QjY_lpc/0/da"><img src="http://feedads.g.doubleclick.net/~a/pAecAOldIFX4wNyfEKG8QjY_lpc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/pAecAOldIFX4wNyfEKG8QjY_lpc/1/da"><img src="http://feedads.g.doubleclick.net/~a/pAecAOldIFX4wNyfEKG8QjY_lpc/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://blogchuck.com/2010/02/domain-validation-class-updated/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blogchuck.com/2010/02/domain-validation-class-updated/</feedburner:origLink></item>
		<item>
		<title>AJAX Loading Image Generation Web 2.0</title>
		<link>http://feedproxy.google.com/~r/JustChuck/~3/2_7b7rqYYfw/</link>
		<comments>http://blogchuck.com/2010/01/ajax-loading-image-generation-web-2-0/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 03:25:20 +0000</pubDate>
		<dc:creator>Chuck Burgess</dc:creator>
				<category><![CDATA[Websites]]></category>

		<guid isPermaLink="false">http://blogchuck.com/?p=295</guid>
		<description><![CDATA[Generate animated loading .gifs for Ajax processes.]]></description>
			<content:encoded><![CDATA[<p>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 <a href="http://ajaxload.info/" target="_blank">http://ajaxload.info/</a> and get yours today!</p>

<p><a href="http://feedads.g.doubleclick.net/~a/i1CMMuznIxM8oXDZ9eMcXsU4o_8/0/da"><img src="http://feedads.g.doubleclick.net/~a/i1CMMuznIxM8oXDZ9eMcXsU4o_8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/i1CMMuznIxM8oXDZ9eMcXsU4o_8/1/da"><img src="http://feedads.g.doubleclick.net/~a/i1CMMuznIxM8oXDZ9eMcXsU4o_8/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://blogchuck.com/2010/01/ajax-loading-image-generation-web-2-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blogchuck.com/2010/01/ajax-loading-image-generation-web-2-0/</feedburner:origLink></item>
	</channel>
</rss>
