<?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>shepherdweb.com &#187; php</title>
	<atom:link href="http://shepherdweb.com/category/web-code/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://shepherdweb.com</link>
	<description>Shane Shepherd: web design and development; music</description>
	<lastBuildDate>Wed, 11 Nov 2009 01:46:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Undefined index: action in /cake/dispatcher.php line 144</title>
		<link>http://shepherdweb.com/2007/04/02/undefined-index-action-in-cakedispatcherphp-line-144/</link>
		<comments>http://shepherdweb.com/2007/04/02/undefined-index-action-in-cakedispatcherphp-line-144/#comments</comments>
		<pubDate>Tue, 03 Apr 2007 02:32:07 +0000</pubDate>
		<dc:creator>Shane</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.shepherdweb.com/2007/04/02/undefined-index-action-in-cakedispatcherphp-line-144/</guid>
		<description><![CDATA[It took me almost an hour to figure out what was causing this error. Undefined index: action in /cake/dispatcher.php line 144 The problem turned out to be that one of the values in $property["Listing"] was returning a value which included a space. Something like this: &#8220;396 &#8220;. Since the requestAction method uses a URL to [...]]]></description>
			<content:encoded><![CDATA[<p>It took me almost an hour to figure out what was causing this error.</p>
<blockquote><p>Undefined index: action in /cake/dispatcher.php line 144</p>
</blockquote>
<p><code class="block"><?php<br />
$aInfo = $this->requestAction('/tours/GetAgentInfo/' . $property["Listing"]["agent"] . '/' . $property["Listing"]["listingoffice"]);<br />
?></code></p>
<p>The problem turned out to be that one of the values in <code>$property["Listing"]</code> was returning a value which included a <kbd>space</kbd>.  Something like this: &#8220;396 &#8220;.  Since the <code>requestAction</code> method uses a URL to get it&#8217;s parameters, it was bombing when the URL looked like this: &#8216;/tours/GetAgentInfo/396 /94&#8242;.  I used the php <code>trim()</code> function to remove spaces, and presto&hellip; problem solved!</p>
<p><code class="block"><?php<br />
$aInfo = $this->requestAction('/tours/GetAgentInfo/' . trim($property["Listing"]["agent"]) . '/' . trim($property["Listing"]["listingoffice"]));<br />
?></code></p>
<div class="techtags"><p>Technorati Tags: <a href="http://technorati.com/tag/CakePHP" rel="tag">CakePHP</a>, <a href="http://technorati.com/tag/PHP" rel="tag"> PHP</a></p></div>
]]></content:encoded>
			<wfw:commentRss>http://shepherdweb.com/2007/04/02/undefined-index-action-in-cakedispatcherphp-line-144/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PHP Link Flood</title>
		<link>http://shepherdweb.com/2006/10/19/php-link-flood/</link>
		<comments>http://shepherdweb.com/2006/10/19/php-link-flood/#comments</comments>
		<pubDate>Fri, 20 Oct 2006 01:27:13 +0000</pubDate>
		<dc:creator>Shane</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[technology & web]]></category>

		<guid isPermaLink="false">http://www.shepherdweb.com/2006/10/19/php-link-flood/</guid>
		<description><![CDATA[My favorite PHP sites: 100% PHP PHP.net PHP-Scripts Blog PHP Developer Marco Tabini PHP Freaks Cake PHP CakePHP The Bakery CakePHP for Beginners H3RALD WithCake Occasional PHP Shaun Inman Snook There and Back Again Technorati Tags: php, links]]></description>
			<content:encoded><![CDATA[<p>My favorite <acronym title="Hypertext Pre-Processor">PHP</acronym> sites:</p>
<h2>100% PHP</h2>
<ul>
<li><a href="http://php.net/">PHP.net</a></li>
<li><a href="http://www.php-scripts.com/phpblog.php">PHP-Scripts Blog</a></li>
<li><a href="http://www.phpdeveloper.org/">PHP Developer</a></li>
<li><a href="http://blogs.phparch.com/mt/">Marco Tabini</a></li>
<li><a href="http://www.phpfreaks.com/">PHP Freaks</a></li>
</ul>
<h2>Cake PHP</h2>
<ul>
<li><a href="http://cakephp.org/">CakePHP</a></li>
<li><a href="http://bakery.cakephp.org/">The Bakery</a></li>
<li><a href="http://grahambird.co.uk/cake/">CakePHP for Beginners</a></li>
<li><a href="http://www.h3rald.com/" title="Fabio Cevasco">H3RALD</a></li>
<li><a href="http://withcake.com/">WithCake</a></li>
</ul>
<h2>Occasional PHP</h2>
<ul>
<li><a href="http://www.shauninman.com/">Shaun Inman</a></li>
<li><a href="http://www.snook.ca/jonathan/" title="Jonathan Snook">Snook</a></li>
<li><a href="http://blog.joshuaeichorn.com/" title="Joshua Eichorn">There and Back Again</a></li>
</ul>
<div class="techtags"><p>Technorati Tags: <a href="http://technorati.com/tag/php" rel="tag">php</a>, <a href="http://technorati.com/tag/links" rel="tag"> links</a></p></div>
]]></content:encoded>
			<wfw:commentRss>http://shepherdweb.com/2006/10/19/php-link-flood/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Editing hasAndBelongsToMany (HABTM) Relationships in CakePHP</title>
		<link>http://shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/</link>
		<comments>http://shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/#comments</comments>
		<pubDate>Tue, 22 Aug 2006 02:47:16 +0000</pubDate>
		<dc:creator>Shane</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/</guid>
		<description><![CDATA[I had a difficult time wrapping my head around how to do this. The manual is not much help. I did get a few clues from a couple of Wiki articles, but in the end I had to piece all this together with stuff I dug out of the CakePHP Google Group. Let&#8217;s assume we [...]]]></description>
			<content:encoded><![CDATA[<p>I had a difficult time wrapping my head around how to do this.  The <a href="http://manual.cakephp.org/">manual</a> is not much help.  I did get a few clues from a couple of <a href="http://wiki.cakephp.org/docs:understanding_associations">Wiki</a> <a href="http://wiki.cakephp.org/docs:method:read">articles</a>, but in the end I had to piece all this together with stuff I dug out of the <a href="http://groups.google.com/group/cake-php">CakePHP Google Group</a>.</p>
<p>Let&#8217;s assume we have two tables, colors and products.  Our model states that products <code>hasAndBelongsToMany</code> colors.  Also, colors <code>hasAndBelongsToMany</code> products.  </p>
<p>Add the following code to app_controller.php:<br />
<code class="block"><br />
	function getSelectedItems($data)<br />
	{<br />
		$return = array();<br />
        foreach ($data as $row)<br />
        {<br />
            $return[$row['id']] = $row['name'];<br />
        }<br />
        return $return;<br />
	}<br />
</code></p>
<p>Our edit function in the products_controller.php will look something like this:<br />
<code class="block"><br />
	function admin_edit($id = null)<br />
	{<br />
		if (empty($this->data))<br />
		{<br />
			$this->set('colors', $this->requestAction('/colors/select'));<br />
// get data for colors DropDownList<br />
$this->Product->id = $id;<br />
$this->data = $this->Product->read();<br />
$this->set('selected_colors', $this->getSelectedItems($this->data['Color']));<br />
		}<br />
		else<br />
		{<br />
		if ($this->Product->save($this->data))<br />
		{<br />
		$this->flash("Your product has been updated.", '/admin/products');<br />
			}<br />
			else<br />
			{<br />
				$this->flash("Unable to update your product.", '/admin/products');<br />
			}<br />
		}<br />
	}<br />
</code></p>
<p>And finally, the code for the multi-select:<br />
<code class="block"><br />
<?=$html->selectTag("Color/Color", $colors, $selected_colors, array('multiple' => 'multiple'))?><br />
</code></p>
<p>If the associations are set up correctly, Cake will automagically save the updated colors when <code>$this->Product->save($this->data)</code> is called in the products controller.  I hope this is helpful to someone, I spent a lot of time digging it up!</p>
<div class="techtags"><p>Technorati Tags: <a href="http://technorati.com/tag/cakephp" rel="tag">cakephp</a>, <a href="http://technorati.com/tag/HATBM" rel="tag"> HATBM</a>, <a href="http://technorati.com/tag/hasAndBelongsToMany" rel="tag"> hasAndBelongsToMany</a></p></div>
]]></content:encoded>
			<wfw:commentRss>http://shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Single User Admin Area Authentication with CakePHP</title>
		<link>http://shepherdweb.com/2006/07/14/single-user-admin-area-authentication-with-cakephp/</link>
		<comments>http://shepherdweb.com/2006/07/14/single-user-admin-area-authentication-with-cakephp/#comments</comments>
		<pubDate>Sat, 15 Jul 2006 02:52:39 +0000</pubDate>
		<dc:creator>Shane</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.shepherdweb.com/2006/07/14/single-user-admin-area-authentication-with-cakephp/</guid>
		<description><![CDATA[This script is mostly the work of Shunro Dozono with some tweaks of my own to make it work with a path to /admin. It handles simple administrator authentication for a single user. Ok, here it goes&#8230; Pre-requisite: CakePHP First, download Shuro&#8217;s component, sd_auth. Copy and paste the code into a file called sd_auth.php and [...]]]></description>
			<content:encoded><![CDATA[<p>This script is mostly the work of <a href="http://cakephp.seesaa.net/">Shunro Dozono</a> with some tweaks of my own to make it work with a path to /admin.  It handles simple administrator authentication for a single user.  Ok, here it goes&#8230;</p>
<p>Pre-requisite: CakePHP</p>
<p>First,  download Shuro&#8217;s component, <a href="http://cakeforge.org/snippet/detail.php?type=snippet&#038;id=92">sd_auth</a>.  Copy and paste the code into a file called sd_auth.php and put it inside app/controllers/components.</p>
<p>Now, create app_controller.php in app/ and paste the code below:</p>
<p><code class="block"> class AppController extends Controller<br />
{<br />
var $components = array('SdAuth');<br />
function adminAuth()<br />
{<br />
// Auth Check.<br />
if($this->SdAuth->isloggedin() == FALSE)<br />
{<br />
$this->layout = "admin_login";<br />
} else {<br />
$this->layout = "admin";<br />
}<br />
}<br />
}</code></p>
<p>Next, uncomment the following line in app/config/core.php:</p>
<p><code class="block">define('CAKE_ADMIN', 'admin');</code></p>
<p>Now, if you pre-pend a function in any of your controllers with &#8220;admin_&#8221; (eg: admin_add) it will now be accessed via the path /admin/add.  Insert the authentication call at the beginning of each one of those functions:</p>
<p><code class="block">function admin_add()<br />
{<br />
$this->adminAuth();<br />
}</code></p>
<p>&#8230;and that method will be authenticated before continuing! Thanks for the tip Shunro.</p>
<div class="techtags"><p>Technorati Tags: <a href="http://technorati.com/tag/cakephp" rel="tag">cakephp</a>, <a href="http://technorati.com/tag/authentication" rel="tag"> authentication</a>, <a href="http://technorati.com/tag/php" rel="tag"> php</a></p></div>
]]></content:encoded>
			<wfw:commentRss>http://shepherdweb.com/2006/07/14/single-user-admin-area-authentication-with-cakephp/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Tiptoe Through the Frameworks</title>
		<link>http://shepherdweb.com/2006/07/03/tiptoe-through-the-frameworks/</link>
		<comments>http://shepherdweb.com/2006/07/03/tiptoe-through-the-frameworks/#comments</comments>
		<pubDate>Mon, 03 Jul 2006 18:49:01 +0000</pubDate>
		<dc:creator>Shane</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Prado]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.shepherdweb.com/2006/07/03/tiptoe-through-the-frameworks/</guid>
		<description><![CDATA[Preface Almost two years ago I jumped into ASP.NET and C# headfirst. This was my first exposure to OOP. I love it, and I don&#8217;t plan on turning back. However, for personal projects and freelancing I prefer to use PHP. PHP was my first &#8220;server-side&#8221; language (not counting a really small ASP email script I [...]]]></description>
			<content:encoded><![CDATA[<h3>Preface</h3>
<p>Almost two years ago I jumped into ASP.NET and C# headfirst.  This was my first exposure to <acronym title="Object Oriented Programming">OOP</acronym>.  I love it, and I don&#8217;t plan on turning back.  However, for personal projects and freelancing I prefer to use PHP.  PHP was my first &#8220;server-side&#8221; language (not counting a <em>really</em> small ASP email script I <del>wrote</del> <ins>leveraged</ins> on my very first freelance development gig).  I love it for it&#8217;s straight forward nature, low cost, and great support.</p>
<p>Many of the conveniences that ASP.NET offers are not inherently available with PHP.  This, and the chest-beating of many <acronym title="Ruby on Rails">RoR</acronym> developers, has led me on a quest for a useful Framework for PHP.</p>
<h3>The Quest Begins</h3>
<p>I began by simply <a href="http://www.google.com/search?hl=en&#038;q=php+frameworks&#038;btnG=Google+Search">googling &#8220;php frameworks&#8221;</a>.  This returned a plethora of comparisons and reviews which I began to peruse.  Along the way I learned some new  terminology: <a href="http://en.wikipedia.org/wiki/Model-view-controller">Model-View-Controller</a>.  Four frameworks stood out to me based on feature set, community, support, and cost (free!).</p>
<h3>The Frameworks</h3>
<h4><a href="http://www.pradosoft.com/">Prado</a></h4>
<p>I was initially impressed by several things about Prado:</p>
<ol>
<li>Currently on version 3 and has a two year track record</li>
<li>It has an active community</li>
<li>It&#8217;s methodology is very similar to ASP.NET</li>
<li>The majority of the Framework is very well documented</li>
<li>Native development for PHP 5</li>
</ol>
<p>Based on these strengths I decided to try Prado first.  I found it easy to install and begin building applications.  I built a simple login and used their templating system.  Overall, I found the entire environment very friendly familiar.  However, Prado suffers from some performance hits because of it&#8217;s architecture when using complicated dynamic templates.  For this reason I decided to continue my quest.  However, I would recommend Prado to anyone coming from ASP.NET who is developing small to medium sized applications.</p>
<h4><a href="http://www.symfony-project.com/">Symfony</a></h4>
<p>Symfony seemed like the next logical progression.  It is well documented, highly reviewed, and seems to be very robust and efficient.  I spent about an hour tooling around the documentation. I decided to abandon Symfony and move on after reading the <a href="http://www.symfony-project.com/content/book/page/installation.html">installation documentation</a>  Please don&#8217;t judge me, I just get nervous when I have to do that much jockeying around with the command line.</p>
<h4><a href="http://cakephp.org/">CakePHP</a></h4>
<p>It looks like I&#8217;m probably going to stick with Cake.</p>
<ol>
<li>Easy to install</li>
<li>Active, enthusiastic community</li>
<li>Good beginner tutorials (unfortunately the remainder of the documentation is still under development and leaves a lot to be desired)</li>
</ol>
<p>I was up and running and had built my first basic application in under an hour using the easy to follow <a href="http://manual.cakephp.org/chapter/20">blog tutorial</a>.  However, as I&#8217;ve tried to dig deeper I&#8217;ve had to dive into <a href="http://groups.google.com/group/cake-php?lnk=li&#038;hl=en">google groups</a>, irc, and other sites for help figuring out the subtleties of Cake.</p>
<h4><a href="http://codeigniter.com/">Code Igniter</a></h4>
<p>I haven&#8217;t tried it yet, but it looks interesting.  If Cake doesn&#8217;t work out, it&#8217;s next on the list.</p>
<div class="techtags"><p>Technorati Tags: <a href="http://technorati.com/tag/php" rel="tag">php</a>, <a href="http://technorati.com/tag/frameworks" rel="tag"> frameworks</a>, <a href="http://technorati.com/tag/prado" rel="tag"> prado</a>, <a href="http://technorati.com/tag/symfony" rel="tag"> symfony</a>, <a href="http://technorati.com/tag/cakephp" rel="tag"> cakephp</a>, <a href="http://technorati.com/tag/codeigniter" rel="tag"> codeigniter</a></p></div>
]]></content:encoded>
			<wfw:commentRss>http://shepherdweb.com/2006/07/03/tiptoe-through-the-frameworks/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>5 Life Lessons from PHP</title>
		<link>http://shepherdweb.com/2005/08/21/5-life-lessons-from-php/</link>
		<comments>http://shepherdweb.com/2005/08/21/5-life-lessons-from-php/#comments</comments>
		<pubDate>Mon, 22 Aug 2005 01:07:08 +0000</pubDate>
		<dc:creator>Shane</dc:creator>
				<category><![CDATA[Insight]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.shepherdweb.com/?p=3</guid>
		<description><![CDATA[I spend a lot of time writing code. The average week will consist of anywhere from 40-60 hrs of writing code for websites. While the majority of that time is probably spent writing ASP, HTML, and CSS, I&#8217;m also an enthusiastic PHP and Javascript programmer. I&#8217;m also beginning to delve into ASP.NET with C#, but [...]]]></description>
			<content:encoded><![CDATA[<p>I spend a lot of time writing code.  The average week will consist of anywhere from 40-60 hrs of writing code for websites.  While the majority of that time is probably spent writing <acronym title="Active Server Pages">ASP</acronym>, <acronym title="Hypertext Markup Language">HTML</acronym>, and <acronym title="Cascading Style Sheets">CSS</acronym>, I&#8217;m also an enthusiastic <acronym title="Hypertext Preprocessor">PHP</acronym> and Javascript programmer.  I&#8217;m also beginning to delve into ASP.NET with C#, but would not call myself proficient in that environment yet.</p>
<p>One of my favorite languages to code in is PHP.  PHP is a &#8220;server-side&#8221; language. This means it does all of the work on the server and then sends the results to your browser.  There are a specific set of rules that must be followed carefully or else the code will not work.  It occurred to me that this mirrors some of my life experience.  Here are 5 life lessons that can be illustrated by the simple rules of PHP.</p>
<dl>
<dt style="font-weight: bold;">Look before you leap.</dt>
<dd>Sound advice.  Don&#8217;t take any action before checking out what you&#8217;re getting into.  PHP provides a basic mechanism for dealing with this life principle.<br />
<code style="width: 400px;" class="block"><br />
if (condition) {<br />
    // if the condition is true, do this<br />
} else {<br />
    // here is your fallback plan!<br />
}<br />
</code><br />
How many tears would we avoid in our lives if we made a habit of running a simple <em>if&#8230;then procedure</em> before making a decision?</dd>
<dt style="font-weight: bold;">Persistence can pay off, but don&#8217;t get stuck in an infinite loop.</dt>
<dd>We&#8217;ve all heard about the value of working hard, but what about working smart?  Just like life, PHP provides an easy tool that allows you to pound away at a single task until it is complete.<br />
<code style="width: 400px;" class="block"><br />
while (condition) {<br />
    // continue repeating this until the condition is met.<br />
 }<br />
</code><br />
There is a catch though!  Not every task can be completed by simply pounding away at it.  It&#8217;s up to you to make sure you don&#8217;t get stuck in a cycle with no way to get out of it!	</dd>
<dt style="font-weight: bold;">Cookies can help make new friends.</dt>
<dd>PHP allows you to give cookies to visitors to your website!  A cookie is a small file deposited on the visitors computer that helps you remember who they are and what they like.  If you&#8217;ve given a visitor cookies in the past, it is possible to instantly recall information about them. Your new friend&#8217;s favorite color, their name, or anything else they might have told you about the first time they visited, can be used to customize their experience when they return.  Remember, not everyone likes cookies, so don&#8217;t be forceful (they are your friends after all).  They are usually very nice in moderation though!</dd>
<dt style="font-weight: bold;">Remember lessons learned from past trials.</dt>
<dd>PHP has a built in way to journal any hurdles you overcome and provide notes to yourself if you ever come across the same problem again.  Often, like life, writing code is a bit of a puzzle.  It requires creatively putting together the simple rules of code (life) into steps that will ultimately yield results <em>and</em>, handling any unexpected circumstances that could rudely interrupt your well thought out plan at the wrong moment.  What a great idea, learn from our victories!</dd>
<dt style="font-weight: bold;">Have some constants in your life.</dt>
<dd>Writing code is a lot like solving a math problem.  One of the challenges of manipulating complicating problems is juggling all of the variables.  Variables are nice because they allow you to change what they represent.  However, this is also the tricky part; the more variable you have, the more complicated it is to keep track of the value of each one.  Sometimes, a variable will inadvertently be changed to something it shouldn&#8217;t, and will compromise the integrity of the output.  Thankfully, PHP (and life) allow us to use constants.  Constants represent values that don&#8217;t change!  While this will sometimes make your puzzles more challenging to solve, the end result is that having constants in your equation will give a firm foundation for reliable output.</dd>
</dl>
]]></content:encoded>
			<wfw:commentRss>http://shepherdweb.com/2005/08/21/5-life-lessons-from-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

