<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>Phillip Napieralski &#187; CakePHP</title>
	<atom:link href="http://blog.pnapieralski.com/category/php/cakephp/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pnapieralski.com</link>
	<description>Programmer, Engineer, Researcher.</description>
	<lastBuildDate>Tue, 20 Dec 2011 16:41:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Migrating from CakePHP 1.2.7 to 1.3</title>
		<link>http://blog.pnapieralski.com/php/cakephp/migrating-from-cakephp-1-2-to-1-3/</link>
		<comments>http://blog.pnapieralski.com/php/cakephp/migrating-from-cakephp-1-2-to-1-3/#comments</comments>
		<pubDate>Fri, 21 May 2010 22:05:50 +0000</pubDate>
		<dc:creator>Phillip Napieralski</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://blog.pnapieralski.com/?p=38</guid>
		<description><![CDATA[I decided to migrate one of my in-progress projects to the latest release of CakePHP (1.3). My experience was quick and painless, and perhaps this writing will benefit someone...]]></description>
			<content:encoded><![CDATA[<p>I decided to migrate one of my in-progress projects to the latest release of CakePHP (1.3). My experience was quick and painless, and perhaps this writing will benefit someone.</p>
<h2>Copy/Overwrite</h2>
<p>Copy/overwrite app/config/core.php, in this file change the following</p>
<ul>
<li>Change cipherSeed value to something other than the default</li>
<li>Change the salt value to the same value you had before</li>
</ul>
<p>Copy/overwrite app/webroot/index.php</p>
<p>Lastly, completely copy over the latest cake, plugins and vendors folders. I didn&#8217;t need to do any other modifications to the app folder other than those stated above.</p>
<h2>Add to Code</h2>
<p>Add &#8216;Session&#8217; to the helpers AND components array in app/app_controller.php like so</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
class AppController extends Controller {
	var $components = array( ..., 'Session');    // Components used in controllers
	var $helpers = array( ..., 'Session' );         // Helpers used in views
}
?&gt;
</pre>
<p>Also,<br />
If using the <strong>Cookie</strong> Component anywhere, change any reference to del() to delete()</p>
<p>Lastly, $session->flash() no longer auto echoes (this code is probably in your layout). I had to change it like so in my code:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
echo $session-&gt;flash();
echo $session-&gt;flash('auth');
?&gt;
</pre>
<h2>Debug Information</h2>
<p>The variable $cakeDebug no longer exists. Instead, use the following code</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php echo $this-&gt;element('sql_dump'); ?&gt;
</pre>
<p>That&#8217;s all I had to do! Everything I mentioned here can be found in the <a href="http://book.cakephp.org/view/1561/Migrating-from-CakePHP-1-2-to-1-3">CakePHP migration guide</a>.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://www.shareaholic.com/api/share/?title=Migrating+from+CakePHP+1.2.7+to+1.3&amp;link=http://blog.pnapieralski.com/php/cakephp/migrating-from-cakephp-1-2-to-1-3/&amp;notes=I%20decided%20to%20migrate%20one%20of%20my%20in-progress%20projects%20to%20the%20latest%20release%20of%20CakePHP%20%281.3%29.%20My%20experience%20was%20quick%20and%20painless%2C%20and%20perhaps%20this%20writing%20will%20benefit%20someone...&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%2524%257Btitle%257D%2B-%2B%2524%257Bshort_link%257D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-digg">
			<a href="http://www.shareaholic.com/api/share/?title=Migrating+from+CakePHP+1.2.7+to+1.3&amp;link=http://blog.pnapieralski.com/php/cakephp/migrating-from-cakephp-1-2-to-1-3/&amp;notes=I%20decided%20to%20migrate%20one%20of%20my%20in-progress%20projects%20to%20the%20latest%20release%20of%20CakePHP%20%281.3%29.%20My%20experience%20was%20quick%20and%20painless%2C%20and%20perhaps%20this%20writing%20will%20benefit%20someone...&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=3&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-reddit">
			<a href="http://www.shareaholic.com/api/share/?title=Migrating+from+CakePHP+1.2.7+to+1.3&amp;link=http://blog.pnapieralski.com/php/cakephp/migrating-from-cakephp-1-2-to-1-3/&amp;notes=I%20decided%20to%20migrate%20one%20of%20my%20in-progress%20projects%20to%20the%20latest%20release%20of%20CakePHP%20%281.3%29.%20My%20experience%20was%20quick%20and%20painless%2C%20and%20perhaps%20this%20writing%20will%20benefit%20someone...&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-technorati">
			<a href="http://www.shareaholic.com/api/share/?title=Migrating+from+CakePHP+1.2.7+to+1.3&amp;link=http://blog.pnapieralski.com/php/cakephp/migrating-from-cakephp-1-2-to-1-3/&amp;notes=I%20decided%20to%20migrate%20one%20of%20my%20in-progress%20projects%20to%20the%20latest%20release%20of%20CakePHP%20%281.3%29.%20My%20experience%20was%20quick%20and%20painless%2C%20and%20perhaps%20this%20writing%20will%20benefit%20someone...&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=10&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.shareaholic.com/api/share/?title=Migrating+from+CakePHP+1.2.7+to+1.3&amp;link=http://blog.pnapieralski.com/php/cakephp/migrating-from-cakephp-1-2-to-1-3/&amp;notes=I%20decided%20to%20migrate%20one%20of%20my%20in-progress%20projects%20to%20the%20latest%20release%20of%20CakePHP%20%281.3%29.%20My%20experience%20was%20quick%20and%20painless%2C%20and%20perhaps%20this%20writing%20will%20benefit%20someone...&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.shareaholic.com/api/share/?title=Migrating+from+CakePHP+1.2.7+to+1.3&amp;link=http://blog.pnapieralski.com/php/cakephp/migrating-from-cakephp-1-2-to-1-3/&amp;notes=I%20decided%20to%20migrate%20one%20of%20my%20in-progress%20projects%20to%20the%20latest%20release%20of%20CakePHP%20%281.3%29.%20My%20experience%20was%20quick%20and%20painless%2C%20and%20perhaps%20this%20writing%20will%20benefit%20someone...&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
</ul><div style="clear: both;"></div><div class="shr-getshr" style="visibility:hidden;font-size:10px !important"><a target="_blank" href="http://www.shareaholic.com/?src=pub">Get Shareaholic</a></div><div style="clear: both;"></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.pnapieralski.com/php/cakephp/migrating-from-cakephp-1-2-to-1-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>User Registration and Login With CakePHP 1.2.x</title>
		<link>http://blog.pnapieralski.com/php/cakephp/user-registration-and-login-with-cakephp/</link>
		<comments>http://blog.pnapieralski.com/php/cakephp/user-registration-and-login-with-cakephp/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 11:02:03 +0000</pubDate>
		<dc:creator>Phillip Napieralski</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://blog.pnapieralski.com/?p=25</guid>
		<description><![CDATA[I'm going to create a simple user registration form with a confirm password field!

Features of this implementation:
<ul>
	<li>Uses AuthComponent</li>
	<li>Confirm password field</li>
	<li>Ensures unique usernames</li>
	<li>User feedback if any errors occur</li>
	<li>Remember me feature (cookies)</li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m going to create a simple user registration form with a confirm password field!</p>
<p>Features of this implementation:</p>
<ul>
<li>Uses AuthComponent</li>
<li>Confirm password field</li>
<li>Ensures unique usernames</li>
<li>User feedback if any errors occur</li>
<li>Remember me feature (cookies)</li>
</ul>
<h2>Prerequisites</h2>
<p>I assume you have a database structure similar to the following:</p>
<div id="attachment_26" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.pnapieralski.com/wp-content/uploads/2010/02/asdf.png" rel="shadowbox[sbpost-25];player=img;"><img class="size-medium wp-image-26" title="Database Layout of Users and Groups Tables" src="http://blog.pnapieralski.com/wp-content/uploads/2010/02/asdf-300x154.png" alt="Users and Groups tables" width="300" height="154" /></a><p class="wp-caption-text"> </p></div>
<p>Note: CakePHP automagically updates the created and modified fields.</p>
<h2>App Controller</h2>
<p>Place the following code in <em>/app/controllers/app_controller.php</em></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

class AppController extends Controller {
	var $components = array( 'Auth', 'RememberMe' );

	function beforeFilter() {
		$this-&gt;Auth-&gt;logoutRedirect =  '/';
		$this-&gt;Auth-&gt;loginRedirect = '/';
		$this-&gt;RememberMe-&gt;check();
	}
}
?&gt;
</pre>
<p>The two lines $this-&gt;Auth-&gt;log*** determine where the user is directed after they login. Another option (instead of &#8216;/&#8217;), is <em>$this-&gt;referer()</em>. That will bring the user back to the page they were just at (sweet)!</p>
<p>What&#8217;s this remember me crap though?</p>
<h2>Remember Me</h2>
<p><a href="http://dsi.vozibrale.com/articles/view/rememberme-component-for-cakephp">This guy</a> wrote an excellent component that you can simply pop in your <em>/app/controllers/components</em> folder and you&#8217;re ready to go.</p>
<h2>The Form</h2>
<p>Place the following code in <em>/app/views/users/register.ctp</em></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
	echo $form-&gt;create('User', array( 'url' =&gt; array( 'action' =&gt; 'register' ) ) );
	echo $form-&gt;input('username',
					 	array('after' =&gt; $form-&gt;error('username_unique', 'The username is taken. Do try again!' ) ) );
	echo $form-&gt;input('password');
	echo $form-&gt;input('confirm_password', array( 'type' =&gt; 'password' ) );
	echo $form-&gt;input('email');
	echo $form-&gt;end('Sign-up');
?&gt;
</pre>
<p>The only tricky piece right now should be in the username piece. In the second parameter, I specified &#8216;after&#8217; that associates with a $form-&gt;error(&#8230;). The username_unique property is something I will define in the User Model shortly.</p>
<h2>Users Controller</h2>
<p>Place the following code in <em>/app/controllers/users_controller.php</em> <strong>inside</strong> your UsersController class.</p>
<pre class="brush: php; title: ; notranslate">
	function beforeFilter()
	{
		parent::beforeFilter();

		// This allows our login() function to execute
		$this-&gt;Auth-&gt;autoRedirect = false;
	}

	// Note, this function is called AFTER Auth has handled it, but BEFORE redirecting to the afterLogin redirect specified (because of the flag we set in beforeFilter)
	// Basically, this means the password field is already encrypted and the session was already created. Easy! =)
	function login()
	{
		// Check if Auth got a hold of it and created a session
		if( $this-&gt;Auth-&gt;user() )
		{
			// If form data was sent, set the remember_me cookie IF they checked the box
			if( isset( $this-&gt;data ) )
			{
				if( empty( $this-&gt;data['User']['remember_me'] ) || $this-&gt;data['User']['remember_me'] == 0 )
				{
					$this-&gt;RememberMe-&gt;delete();
				}
				else
				{
					$this-&gt;RememberMe-&gt;remember(
								$this-&gt;data['User']['username'],
								$this-&gt;data['User']['password'] );
				}

				$this-&gt;Session-&gt;setFlash('You are logged in!');
			}

			// Redirect to our loginRedirect page specified
			$this-&gt;redirect($this-&gt;Auth-&gt;redirect());
		}
	}

	function logout(){
		// Set logout message and call auth component's logout
		$this-&gt;Session-&gt;setFlash('You are logged out! Good bye!');

		// Delete the cookie
		$this-&gt;RememberMe-&gt;delete();

		// Call Auth to delete our session
		$this-&gt;redirect($this-&gt;Auth-&gt;logout());
	}

	function register() {
		if ( isset($this-&gt;data) )
		{
			// Set group to regular user
			//    NOTE: This may be different for you
			$this-&gt;data['User']['group_id'] = 2;

			$this-&gt;User-&gt;create();
			if ($this-&gt;User-&gt;save($this-&gt;data))
			{
				$this-&gt;Session-&gt;setFlash( 'Thank you for registering!' );
				$this-&gt;redirect(array('action'=&gt;'index'));
			}
			else
			{
				// Make the password fields blank
				unset($this-&gt;data['User']['password']);
				unset($this-&gt;data['User']['confirm_password']);

				$this-&gt;Session-&gt;setFlash('An error occurred, try again!');
			}
		}
	}
</pre>
<p>Excellent! Now we just have one more step&#8230; let&#8217;s validate the user&#8217;s input.</p>
<h2>The User Model</h2>
<p>Place the following code in <em>/app/models/user.php</em></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
class User extends AppModel {

	var $name = 'User';

	// Prevent the input from having an id
	// Username: MUST be alphanumeric
	// Password: We specify a function that returns a bool value
	var $validate = array(
		'id' =&gt; array(
							'rule' =&gt; 'blank',
							'on' =&gt; 'create'
					 ),
		'username' =&gt; array(
							'rule' =&gt; 'alphanumeric',
							'message' =&gt; 'Please enter a valid username',
							'required' =&gt; true
						),
		'password' =&gt; array(
							'rule' =&gt; array('confirmPassword', 'password'),
							'message' =&gt; 'Passwords do not match',
							'required' =&gt; 'true'
						),
		'confirm_password' =&gt; array(
							'rule' =&gt; 'alphanumeric',
							'required' =&gt; 'true'
						),
		'email' =&gt; array( 'email',
							array( 'rule' =&gt; array('email'),
									'message' =&gt; 'Please enter a valid email!' )
						),
		'group_id' =&gt; array( 'numeric' )
	);

	function confirmPassword($data)
	{
		// We must manually hash the second piece in the same way the AuthComponent would
		// if they match, return true!
		if ($data['password'] == Security::hash(Configure::read('Security.salt') . $this-&gt;data['User']['confirm_password'])) {
			return true;
		}

		// hashed passwords did NOT match
		return false;
	}

	// Check if the username already exists by doing SELECT COUNT(*) FROM users WHERE username = 'your_username'
	function beforeValidate()
	{
		if( !$this-&gt;id )
		{
			if( $this-&gt;findCount( array('User.username' =&gt; $this-&gt;data['User']['username'] ) ) &gt; 0 )
			{
				// If any rows are found, send an error and call it 'username_unique'
				// In our view, we can check for this by doing $form-&gt;error('username_unique','Not Unique Username!!!')
				//   As specified in the view code I placed above
				$this-&gt;invalidate('username_unique');
				return false;
			}
		}
		return true;
	}

	// Associations
	var $belongsTo = 'Group';
}
?&gt;
</pre>
<p>Great!</p>
<h2>Conclusion</h2>
<p>There you have it. Something that may take you places in your projects (hopefully). Any questions?</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://www.shareaholic.com/api/share/?title=User+Registration+and+Login+With+CakePHP+1.2.x&amp;link=http://blog.pnapieralski.com/php/cakephp/user-registration-and-login-with-cakephp/&amp;notes=I%27m%20going%20to%20create%20a%20simple%20user%20registration%20form%20with%20a%20confirm%20password%20field%21%0D%0A%0D%0AFeatures%20of%20this%20implementation%3A%0D%0A%0D%0A%09Uses%20AuthComponent%0D%0A%09Confirm%20password%20field%0D%0A%09Ensures%20unique%20usernames%0D%0A%09User%20feedback%20if%20any%20errors%20occur%0D%0A%09Remember%20me%20feature%20%28cookies%29%0D%0A&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%2524%257Btitle%257D%2B-%2B%2524%257Bshort_link%257D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-digg">
			<a href="http://www.shareaholic.com/api/share/?title=User+Registration+and+Login+With+CakePHP+1.2.x&amp;link=http://blog.pnapieralski.com/php/cakephp/user-registration-and-login-with-cakephp/&amp;notes=I%27m%20going%20to%20create%20a%20simple%20user%20registration%20form%20with%20a%20confirm%20password%20field%21%0D%0A%0D%0AFeatures%20of%20this%20implementation%3A%0D%0A%0D%0A%09Uses%20AuthComponent%0D%0A%09Confirm%20password%20field%0D%0A%09Ensures%20unique%20usernames%0D%0A%09User%20feedback%20if%20any%20errors%20occur%0D%0A%09Remember%20me%20feature%20%28cookies%29%0D%0A&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=3&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-reddit">
			<a href="http://www.shareaholic.com/api/share/?title=User+Registration+and+Login+With+CakePHP+1.2.x&amp;link=http://blog.pnapieralski.com/php/cakephp/user-registration-and-login-with-cakephp/&amp;notes=I%27m%20going%20to%20create%20a%20simple%20user%20registration%20form%20with%20a%20confirm%20password%20field%21%0D%0A%0D%0AFeatures%20of%20this%20implementation%3A%0D%0A%0D%0A%09Uses%20AuthComponent%0D%0A%09Confirm%20password%20field%0D%0A%09Ensures%20unique%20usernames%0D%0A%09User%20feedback%20if%20any%20errors%20occur%0D%0A%09Remember%20me%20feature%20%28cookies%29%0D%0A&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-technorati">
			<a href="http://www.shareaholic.com/api/share/?title=User+Registration+and+Login+With+CakePHP+1.2.x&amp;link=http://blog.pnapieralski.com/php/cakephp/user-registration-and-login-with-cakephp/&amp;notes=I%27m%20going%20to%20create%20a%20simple%20user%20registration%20form%20with%20a%20confirm%20password%20field%21%0D%0A%0D%0AFeatures%20of%20this%20implementation%3A%0D%0A%0D%0A%09Uses%20AuthComponent%0D%0A%09Confirm%20password%20field%0D%0A%09Ensures%20unique%20usernames%0D%0A%09User%20feedback%20if%20any%20errors%20occur%0D%0A%09Remember%20me%20feature%20%28cookies%29%0D%0A&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=10&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.shareaholic.com/api/share/?title=User+Registration+and+Login+With+CakePHP+1.2.x&amp;link=http://blog.pnapieralski.com/php/cakephp/user-registration-and-login-with-cakephp/&amp;notes=I%27m%20going%20to%20create%20a%20simple%20user%20registration%20form%20with%20a%20confirm%20password%20field%21%0D%0A%0D%0AFeatures%20of%20this%20implementation%3A%0D%0A%0D%0A%09Uses%20AuthComponent%0D%0A%09Confirm%20password%20field%0D%0A%09Ensures%20unique%20usernames%0D%0A%09User%20feedback%20if%20any%20errors%20occur%0D%0A%09Remember%20me%20feature%20%28cookies%29%0D%0A&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.shareaholic.com/api/share/?title=User+Registration+and+Login+With+CakePHP+1.2.x&amp;link=http://blog.pnapieralski.com/php/cakephp/user-registration-and-login-with-cakephp/&amp;notes=I%27m%20going%20to%20create%20a%20simple%20user%20registration%20form%20with%20a%20confirm%20password%20field%21%0D%0A%0D%0AFeatures%20of%20this%20implementation%3A%0D%0A%0D%0A%09Uses%20AuthComponent%0D%0A%09Confirm%20password%20field%0D%0A%09Ensures%20unique%20usernames%0D%0A%09User%20feedback%20if%20any%20errors%20occur%0D%0A%09Remember%20me%20feature%20%28cookies%29%0D%0A&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
</ul><div style="clear: both;"></div><div class="shr-getshr" style="visibility:hidden;font-size:10px !important"><a target="_blank" href="http://www.shareaholic.com/?src=pub">Get Shareaholic</a></div><div style="clear: both;"></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.pnapieralski.com/php/cakephp/user-registration-and-login-with-cakephp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP Cheatsheets</title>
		<link>http://blog.pnapieralski.com/php/cakephp/cakephp-cheatsheets/</link>
		<comments>http://blog.pnapieralski.com/php/cakephp/cakephp-cheatsheets/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 23:32:11 +0000</pubDate>
		<dc:creator>Phillip Napieralski</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://blog.pnapieralski.com/?p=23</guid>
		<description><![CDATA[This is a list of cheatsheets and links for things that I commonly use (and forget the syntax to) in CakePHP.]]></description>
			<content:encoded><![CDATA[<p>This is a list of cheatsheets and links for things that I commonly use (and forget the syntax to) in CakePHP.</p>
<ul>
<li><a href="http://cakephp.org/files/Resources/CakePHP-1.2-Cheatsheet.pdf">Official Cake Cheatsheet</a></li>
<li><a href="http://book.cakephp.org/view/205/HTML">HtmlHelper</a></li>
<li><a href="http://book.cakephp.org/view/182/form">FormHelper</a></li>
<li><a href="http://book.cakephp.org/view/217/Time">TimeHelper</a></li>
<li><a href="http://blog.pnapieralski.com/wp-content/uploads/2010/02/cakephp1.2-model-associations-1-1.pdf">Model Associations</a></li>
<li><a title="Retrieving Data - Find" href="http://book.cakephp.org/view/73/Retrieving-Your-Data">Retrieving Data &#8211; Find</a></li>
<li><a title="Find between CakePHP" href="http://devdaily.com/php/cakephp-find-between-select-query-syntax">Retrieving Data &#8211; More Find stuff</a></li>
<li><a href="http://book.cakephp.org/view/165/Controller-Setup">Pagination</a></li>
</ul>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://www.shareaholic.com/api/share/?title=CakePHP+Cheatsheets&amp;link=http://blog.pnapieralski.com/php/cakephp/cakephp-cheatsheets/&amp;notes=This%20is%20a%20list%20of%20cheatsheets%20and%20links%20for%20things%20that%20I%20commonly%20use%20%28and%20forget%20the%20syntax%20to%29%20in%20CakePHP.&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%2524%257Btitle%257D%2B-%2B%2524%257Bshort_link%257D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-digg">
			<a href="http://www.shareaholic.com/api/share/?title=CakePHP+Cheatsheets&amp;link=http://blog.pnapieralski.com/php/cakephp/cakephp-cheatsheets/&amp;notes=This%20is%20a%20list%20of%20cheatsheets%20and%20links%20for%20things%20that%20I%20commonly%20use%20%28and%20forget%20the%20syntax%20to%29%20in%20CakePHP.&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=3&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-reddit">
			<a href="http://www.shareaholic.com/api/share/?title=CakePHP+Cheatsheets&amp;link=http://blog.pnapieralski.com/php/cakephp/cakephp-cheatsheets/&amp;notes=This%20is%20a%20list%20of%20cheatsheets%20and%20links%20for%20things%20that%20I%20commonly%20use%20%28and%20forget%20the%20syntax%20to%29%20in%20CakePHP.&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-technorati">
			<a href="http://www.shareaholic.com/api/share/?title=CakePHP+Cheatsheets&amp;link=http://blog.pnapieralski.com/php/cakephp/cakephp-cheatsheets/&amp;notes=This%20is%20a%20list%20of%20cheatsheets%20and%20links%20for%20things%20that%20I%20commonly%20use%20%28and%20forget%20the%20syntax%20to%29%20in%20CakePHP.&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=10&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.shareaholic.com/api/share/?title=CakePHP+Cheatsheets&amp;link=http://blog.pnapieralski.com/php/cakephp/cakephp-cheatsheets/&amp;notes=This%20is%20a%20list%20of%20cheatsheets%20and%20links%20for%20things%20that%20I%20commonly%20use%20%28and%20forget%20the%20syntax%20to%29%20in%20CakePHP.&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.shareaholic.com/api/share/?title=CakePHP+Cheatsheets&amp;link=http://blog.pnapieralski.com/php/cakephp/cakephp-cheatsheets/&amp;notes=This%20is%20a%20list%20of%20cheatsheets%20and%20links%20for%20things%20that%20I%20commonly%20use%20%28and%20forget%20the%20syntax%20to%29%20in%20CakePHP.&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
</ul><div style="clear: both;"></div><div class="shr-getshr" style="visibility:hidden;font-size:10px !important"><a target="_blank" href="http://www.shareaholic.com/?src=pub">Get Shareaholic</a></div><div style="clear: both;"></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.pnapieralski.com/php/cakephp/cakephp-cheatsheets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Very Simple User Authentication with CakePHP</title>
		<link>http://blog.pnapieralski.com/php/cakephp/very-simple-user-authentication-with-cakephp/</link>
		<comments>http://blog.pnapieralski.com/php/cakephp/very-simple-user-authentication-with-cakephp/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 08:56:10 +0000</pubDate>
		<dc:creator>Phillip Napieralski</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Software Engineering II]]></category>

		<guid isPermaLink="false">http://blog.pnapieralski.com/?p=22</guid>
		<description><![CDATA[I'm working with my Software Engineering II class to build an online survey for United Way. I was left in charge to create a simple way to login and authenticate.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working with my <a href="http://blog.pnapieralski.com/servers/software-engineering-ii-part-1/">Software Engineering II class</a> to build an online survey for United Way. I was left in charge to create a simple way to login and authenticate.</p>
<p>The following implementation uses sessions exclusively. I built it so you MUST log-in before accessing any part of the site/survey. You could easily build off this, or even switch to Cake&#8217;s built-in <a href="http://book.cakephp.org/view/170/Core-Components">ACL and Auth</a> features.</p>
<h2>Preliminaries</h2>
<p>The database structure presented is the same as in <a href="http://blog.pnapieralski.com/php/user-account-class-in-php-1/">my previous post</a> about a user account class. Here it is again however:</p>
<div id="attachment_15" class="wp-caption alignnone" style="width: 280px"><a href="http://blog.pnapieralski.com/wp-content/uploads/2010/02/usergroup.png" rel="shadowbox[sbpost-22];player=img;"><img class="size-medium wp-image-15  " title="usergroup" src="http://blog.pnapieralski.com/wp-content/uploads/2010/02/usergroup-300x219.png" alt="" width="270" height="197" /></a><p class="wp-caption-text"> </p></div>
<h2>The Login Form View</h2>
<p>The login form is extremely simple using Cake&#8217;s built in form helper. Here&#8217;s how we do it:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
// Pass the model name into the Create function, also pass where the data will be sent
echo $form-&gt;create('User', array( 'controller' =&gt; 'users', 'action' =&gt; 'login' ) );

// Cake automatically knows, based on the input, to create input fields for these two. Cool eh?
echo $form-&gt;input('username');
echo $form-&gt;input('password');

// Create the submit button
echo $form-&gt;end('Login');
?&gt;
</pre>
<p>That&#8217;s much less code, and way clearer once you get used to it. I placed this file in <em>/app/views/users/login_form.ctp</em></p>
<h2>The User Model</h2>
<pre class="brush: php; title: ; notranslate">
&lt;?php
class User extends AppModel {
	function validateLogin($data)
	{
		// Search our database where the 'username' field is equal to our form input.
		// Same with the password (this example uses PLAIN TEXT passwords, you should encrypt yours!)
		// The second parameter tells us which fields to return from the database
		// Here is the corresponding query:
		// &quot;SELECT id, username FROM users WHERE username = 'xxx' AND password = 'yyy'&quot;
		$user = $this-&gt;find(array('username' =&gt; $data['username'], 'password' =&gt; $data['password']), array('id', 'username'));

		if( empty($user) == false )
		{
			return $user;
		}

		return false;
	}
}
?&gt;
</pre>
<p>This code should go in <em>/app/models/user.php</em></p>
<h2>The Users Controller</h2>
<pre class="brush: php; title: ; notranslate">
&lt;?php
class UsersController extends AppController {
	var $name = 'Users';
	var $helpers = array('Form');

	// Placeholder for login_form, required by CakePHP to see the login_form view
	function login_form() { }

	function login() {
		// Check if they went here after submitting the form
		// Note that all our form data is preceded by the model name ['User']
		if(empty($this-&gt;data['User']['username']) == false)
		{
			// Here we validate the user by calling that method from the User model
			if(($user = $this-&gt;User-&gt;validateLogin($this-&gt;data['User'])) != false)
			{
				// Write some Session variables and redirect to our next page!
				$this-&gt;Session-&gt;setFlash('Thank you for logging in!');
				$this-&gt;Session-&gt;write('User', $user);

				// Go to our first destination!
				$this-&gt;Redirect(array('controller' =&gt; 'Controller_name', 'action' =&gt; 'Action_name'));
				exit();
			}
			else
			{
				$this-&gt;Session-&gt;setFlash('Incorrect username/password!', true);
				$this-&gt;Redirect(array('action' =&gt; 'login_form'));
				exit();
			}
		}
	}

	function logout() {

		$this-&gt;Session-&gt;destroy();
		$this-&gt;Session-&gt;setFlash('You have been logged out!');

		// Go home!
		$this-&gt;Redirect('/');
		exit();
	}
}
?&gt;
</pre>
<p>Place this code in <em>/app/controllers/users_controller.php</em></p>
<h2>The AppController &#8211; Validate on Every Page</h2>
<pre class="brush: php; title: ; notranslate">
class AppController extends Controller {

	// Check if they are logged in
	function authenticate()
	{
		// Check if the session variable User exists, redirect to loginform if not
		if(!$this-&gt;Session-&gt;check('User'))
		{
			$this-&gt;redirect(array('controller' =&gt; 'users', 'action' =&gt; 'login_form'));
			exit();
		}
	}

	// Authenticate on every action, except the login form
	function afterFilter()
	{
		if( $this-&gt;action != 'login_form' )
		{
			$this-&gt;authenticate();
		}
	}
}
</pre>
<p>Now simply place this code in <em>/app/app_controller.php</em></p>
<p>What does this do? Well, now no matter where anyone goes on your website, they will be redirected to the login page UNLESS they are logged in! Excellent.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://www.shareaholic.com/api/share/?title=Very+Simple+User+Authentication+with+CakePHP&amp;link=http://blog.pnapieralski.com/php/cakephp/very-simple-user-authentication-with-cakephp/&amp;notes=I%27m%20working%20with%20my%20Software%20Engineering%20II%20class%20to%20build%20an%20online%20survey%20for%20United%20Way.%20I%20was%20left%20in%20charge%20to%20create%20a%20simple%20way%20to%20login%20and%20authenticate.&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%2524%257Btitle%257D%2B-%2B%2524%257Bshort_link%257D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-digg">
			<a href="http://www.shareaholic.com/api/share/?title=Very+Simple+User+Authentication+with+CakePHP&amp;link=http://blog.pnapieralski.com/php/cakephp/very-simple-user-authentication-with-cakephp/&amp;notes=I%27m%20working%20with%20my%20Software%20Engineering%20II%20class%20to%20build%20an%20online%20survey%20for%20United%20Way.%20I%20was%20left%20in%20charge%20to%20create%20a%20simple%20way%20to%20login%20and%20authenticate.&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=3&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-reddit">
			<a href="http://www.shareaholic.com/api/share/?title=Very+Simple+User+Authentication+with+CakePHP&amp;link=http://blog.pnapieralski.com/php/cakephp/very-simple-user-authentication-with-cakephp/&amp;notes=I%27m%20working%20with%20my%20Software%20Engineering%20II%20class%20to%20build%20an%20online%20survey%20for%20United%20Way.%20I%20was%20left%20in%20charge%20to%20create%20a%20simple%20way%20to%20login%20and%20authenticate.&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-technorati">
			<a href="http://www.shareaholic.com/api/share/?title=Very+Simple+User+Authentication+with+CakePHP&amp;link=http://blog.pnapieralski.com/php/cakephp/very-simple-user-authentication-with-cakephp/&amp;notes=I%27m%20working%20with%20my%20Software%20Engineering%20II%20class%20to%20build%20an%20online%20survey%20for%20United%20Way.%20I%20was%20left%20in%20charge%20to%20create%20a%20simple%20way%20to%20login%20and%20authenticate.&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=10&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.shareaholic.com/api/share/?title=Very+Simple+User+Authentication+with+CakePHP&amp;link=http://blog.pnapieralski.com/php/cakephp/very-simple-user-authentication-with-cakephp/&amp;notes=I%27m%20working%20with%20my%20Software%20Engineering%20II%20class%20to%20build%20an%20online%20survey%20for%20United%20Way.%20I%20was%20left%20in%20charge%20to%20create%20a%20simple%20way%20to%20login%20and%20authenticate.&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.shareaholic.com/api/share/?title=Very+Simple+User+Authentication+with+CakePHP&amp;link=http://blog.pnapieralski.com/php/cakephp/very-simple-user-authentication-with-cakephp/&amp;notes=I%27m%20working%20with%20my%20Software%20Engineering%20II%20class%20to%20build%20an%20online%20survey%20for%20United%20Way.%20I%20was%20left%20in%20charge%20to%20create%20a%20simple%20way%20to%20login%20and%20authenticate.&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
</ul><div style="clear: both;"></div><div class="shr-getshr" style="visibility:hidden;font-size:10px !important"><a target="_blank" href="http://www.shareaholic.com/?src=pub">Get Shareaholic</a></div><div style="clear: both;"></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.pnapieralski.com/php/cakephp/very-simple-user-authentication-with-cakephp/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

