<?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>Witheringtree &#187; PHP</title>
	<atom:link href="http://www.witheringtree.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.witheringtree.com</link>
	<description>If a tree falls in the forest and no one is around to hear it fall… yeah, it still makes a sound.</description>
	<lastBuildDate>Mon, 23 Jan 2012 02:07:39 +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>Now I&#8217;m Confused</title>
		<link>http://www.witheringtree.com/2011/09/now-im-confused/</link>
		<comments>http://www.witheringtree.com/2011/09/now-im-confused/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 03:24:32 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Funny]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=950</guid>
		<description><![CDATA[I&#8217;m working on a Magento module and I got an error message saying &#8220;An error occurred while saving the page.&#8221; Right under it I gut a success message saying &#8220;The page has been saved.&#8221;]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a Magento module and I got an error message saying &#8220;An error occurred while saving the page.&#8221; Right under it I gut a success message saying &#8220;The page has been saved.&#8221;</p>
<p><a href="http://www.witheringtree.com/wp-content/uploads/2011/09/fail_but_save.png" rel="shadowbox[sbpost-950];player=img;"><img class="alignnone size-medium wp-image-951" title="fail_but_save" src="http://www.witheringtree.com/wp-content/uploads/2011/09/fail_but_save-300x234.png" alt="" width="300" height="234" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2011/09/now-im-confused/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom CodeIgniter Validation Methods</title>
		<link>http://www.witheringtree.com/2011/09/custom-codeigniter-validation-methods/</link>
		<comments>http://www.witheringtree.com/2011/09/custom-codeigniter-validation-methods/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 21:12:05 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Tips/Tricks]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=944</guid>
		<description><![CDATA[CodeIgniter&#8217;s Form Validation library isn&#8217;t bad. It takes a little getting use to but it can be very powerful. Most of the validation that comes with CodeIgniter are pretty much the only ones you will ever need. Every now and then you will need something else. Extending CodeIgniter libraries is very easy. These are some &#8230; <a href="http://www.witheringtree.com/2011/09/custom-codeigniter-validation-methods/" title="Continue reading">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>CodeIgniter&#8217;s <a href="http://codeigniter.com/user_guide/libraries/form_validation.html" title="CodeIgniter Form Validation" target="_blank">Form Validation</a> library isn&#8217;t bad. It takes a little getting use to but it can be very powerful. Most of the validation that comes with CodeIgniter are pretty much the only ones you will ever need. Every now and then you will need something else. <a href="http://codeigniter.com/user_guide/general/creating_libraries.html" title="Creating and Extending CodeIgniter Libraries" target="_blank">Extending CodeIgniter libraries</a> is very easy. These are some of the custom form validation I&#8217;ve had to do in previous projects</p>
<p>First of all, you have to create a library that will extend CodeIgniter&#8217;s library. Create a new file named MY_Form_validation.php and put it in the application/libraries/ directory. Here is what that library will look like:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BASEPATH'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access allowed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MY_Form_validation <span style="color: #000000; font-weight: bold;">extends</span> CI_Form_validation <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$CI</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CI</span> <span style="color: #339933;">=&amp;</span> get_instance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The first validation method I used for a project where the user would enter a fraction and I didn&#8217;t really want to convert a decimal to a fraction. So I just created a validation method.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Fraction
 *
 * @access  public
 * @param   string  $str
 * @return  bool
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fraction<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_message</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'fraction'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'The %s field must be a valid fraction.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/^(\d++(?! */))? *-? *(?:(\d+) */ *(\d+))?.*$/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #009900; font-weight: bold;">FALSE</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Usage example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'screen_size'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Screen Size'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'fraction'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This was a fun validation to make. When a user signs up or is changing their password, their password must be <a href="http://www.pcicomplianceguide.org/" title="PCI Compliance" target="_blank">PCI compliant</a>. For a password to be PCI compliant, it must meet the following:<br />
1) Must be between 6 and 99 characters in length<br />
2) Must not contain two consecutively repeating characters<br />
3) Must contain at least one upper-case letter<br />
4) Must contain at least one lower-case letter<br />
5) Must contain at least one number<br />
6) Must contain at least one special character</p>
<p>Please note that the validation message is really long. You may want to simplify it a little before using it</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * PCI compliance password
 *
 * @access  public
 * @param   $str
 * @return  bool
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> pci_password<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$special</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'!@#$%*-_=+.'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_message</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pci_password'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'For PCI compliance, %s must be between 6 and 99 characters in length, must not contain two consecutively repeating characters, contain at least one upper-case letter, at least one lower-case letter, at least one number, and at least one special character ('</span><span style="color: #339933;">.</span><span style="color: #000088;">$special</span><span style="color: #339933;">.</span><span style="color: #0000ff;">')'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^(?=^.{6,99}$)(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*['</span><span style="color: #339933;">.</span><span style="color: #000088;">$special</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'])(?!.*?(.)\1{1,})^.*$/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #009900; font-weight: bold;">TRUE</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Usage example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Password'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'pci_password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>CodeIgniter already has a validation method for <em>required</em>. But I needed one to be required if a different field had a value. A couple weeks later I needed to have method to make a field required if another field had a certain value.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Required if another field has a value (related fields) or if a field has a certain value
 *
 * @access  public
 * @param   string  $str
 * @param   string  $field
 * @return  bool
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> required_if<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fld</span><span style="color: #339933;">,</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_message</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'required_if'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'The %s field is required.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// $fld is filled out</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$fld</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Must have specific value</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// Not the specific value we are looking for</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$fld</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$val</span> AND <span style="color: #339933;">!</span> <span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Usage example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bar'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Bar'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'required_if[foo]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// required if field 'foo' has a value</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'foobar'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Foo Bar'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'required_if[foo,bar]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// required if field 'foo' has a value of 'bar'</span></pre></div></div>

<p>There are a lot of examples of this validation floating around. It requires that a value being passed has a unique value in the database. This one also takes into account the database prefix.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Unique
 *
 * @access	public
 * @param	string
 * @param	field
 * @return	bool
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> unique<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #339933;">,</span> <span style="color: #000088;">$column</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_message</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'unique'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'The %s that you requested is already in use.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT COUNT(*) AS dupe FROM {<span style="color: #006699; font-weight: bold;">$this-&gt;CI</span>-&gt;db-&gt;dbprefix(<span style="color: #006699; font-weight: bold;">$table</span>)} WHERE <span style="color: #006699; font-weight: bold;">{$column}</span> = '<span style="color: #006699; font-weight: bold;">{$str}</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">row</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dupe</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> ? <span style="color: #009900; font-weight: bold;">FALSE</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Usage example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Email'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'unique[DBTABLE,DBFIELD]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">// DBTABLE is the database table and DBFIELD is the database field to validation against</span></pre></div></div>

<p>I took the previous validation a step further so that the field value must be unique in the database EXCEPT for a certain record ID. This one is really good for if you have an existing user in the system and they are updating their profile. You want to make sure that their email address is unique. If you run the previous <em>unique</em> validation it will fail because the email address is already in use by the user currently being edited. So we need to exclude that users ID from the validation. This one also takes into account the database prefix.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Unique except. Check if a specific value is in use except when the value is attached to a specific row ID
 *
 * @param	string
 * @param	field
 * @return	bool
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> unique_exclude<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #339933;">,</span> <span style="color: #000088;">$column</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fld</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_message</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'unique_exclude'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'The %s that you requested is already in use.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT COUNT(*) AS dupe FROM {<span style="color: #006699; font-weight: bold;">$this-&gt;CI</span>-&gt;db-&gt;dbprefix(<span style="color: #006699; font-weight: bold;">$table</span>)} WHERE <span style="color: #006699; font-weight: bold;">{$column}</span> = '<span style="color: #006699; font-weight: bold;">$str</span>' AND <span style="color: #006699; font-weight: bold;">{$fld}</span> &lt;&gt; <span style="color: #006699; font-weight: bold;">{$id}</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">row</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dupe</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> ? <span style="color: #009900; font-weight: bold;">FALSE</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Usage example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Email'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'unique[DBTABLE,DBFIELD,IDFIELD,ID]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">// DBTABLE is the database table, DBFIELD is the database field, IDFIELD is the primary key for the table, and ID is the unique ID for the user</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2011/09/custom-codeigniter-validation-methods/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Blocks in Magento</title>
		<link>http://www.witheringtree.com/2011/09/blocks-in-magento/</link>
		<comments>http://www.witheringtree.com/2011/09/blocks-in-magento/#comments</comments>
		<pubDate>Sat, 17 Sep 2011 00:41:11 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=937</guid>
		<description><![CDATA[One of the things Magento got right is blocks. It&#8217;s one of the few things I am continually impressed by. There are a lot of ways to add a static block to the page. XML is probably the most common place to add a static block. You find whatever block you want to add your &#8230; <a href="http://www.witheringtree.com/2011/09/blocks-in-magento/" title="Continue reading">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the things Magento got right is blocks. It&#8217;s one of the few things I am continually impressed by. There are a lot of ways to add a static block to the page.</p>
<p><strong>XML</strong> is probably the most common place to add a static block. You find whatever block you want to add your static block into and you add something like:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;block</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;cms/block&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;YOUR_BLOCK_ID&quot;</span> <span style="color: #000066;">before</span>=<span style="color: #ff0000;">&quot;-&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;setBlockId&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;block_id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>YOUR_BLOCK_ID<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/block_id<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/block<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Adding a static clock through <strong>layout XML</strong> can be very useful if you need to add a static block to a sidebar on a single page for example instead of all pages.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;reference</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;left&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;block</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;cms/block&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;YOUR_BLOCK_ID&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;setBlockId&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;block_id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>YOUR_BLOCK_ID<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/block_id<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/block<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/reference<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Adding you static block through <strong>PHP</strong> may be the least common way. This, however, can be very useful if you want to define areas in your theme where a menu or a widgets could go. To add a static block in PHP you would use:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createBlock</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cms/block'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setBlockId</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'YOUR_BLOCK_ID'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">toHtml</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Adding a static block through a short code is very powerful. It allows you to add a static block into a CMS page or even your products.</p>

<div class="wp_syntax"><div class="code"><pre class="smarty" style="font-family:monospace;"><span style="color: #D36900;">&#123;</span><span style="color: #D36900;">&#123;</span>block type<span style="color: #D36900;">=</span><span style="color: #ff0000;">&quot;cms/block&quot;</span> block_id<span style="color: #D36900;">=</span><span style="color: #ff0000;">&quot;YOUR_BLOCK_ID&quot;</span><span style="color: #D36900;">&#125;</span>}</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2011/09/blocks-in-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting Up Virtual Hosts in Zend Server CE on OS X</title>
		<link>http://www.witheringtree.com/2011/07/setting-up-virtual-hosts-in-zend-server-ce-on-os-x/</link>
		<comments>http://www.witheringtree.com/2011/07/setting-up-virtual-hosts-in-zend-server-ce-on-os-x/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 00:40:19 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Website]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Tips/Tricks]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=930</guid>
		<description><![CDATA[What is a virtual host? Virtual hosting is a method for hosting multiple domain names on a computer using a single IP address. Shared hosting uses this same method for all of the sites they host. Aren&#8217;t those URLs you use in Zend Server getting pretty ugly? Would you like to change http://localhost/my/awesome/website into http://www.super-awesome.local &#8230; <a href="http://www.witheringtree.com/2011/07/setting-up-virtual-hosts-in-zend-server-ce-on-os-x/" title="Continue reading">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
What is a virtual host? Virtual hosting is a method for hosting multiple domain names on a computer using a single IP address. Shared hosting uses this same method for all of the sites they host. Aren&#8217;t those URLs you use in Zend Server getting pretty ugly? Would you like to change http://localhost/my/awesome/website into http://www.super-awesome.local You can!
</p>
<p>
Last time we talked about general Zend Server setup. This time, we will be going through setting up virtual hosts on your local machine. This again will involve Terminal.
</p>
<p>
This assumes you have Zend Server set up and running. If it is not, <a href="http://www.witheringtree.com/2011/07/installing-zend-server-ce-on-os-x-a-guide-for-the-terminal-timid/" title="Installing Zend Server CE on OS X: A Guide For the Terminal Timid">go here</a>.
</p>
<p><span id="more-930"></span></p>
<ol>
<li>
<p>
		Open Terminal. Terminal can be found at /Applications/Utilities/Terminal.app
	</p>
<p>
		You can also open it from Spotlight by typing &#8220;Terminal&#8221;
	</p>
</li>
<li>
<p>
		We are going to edit our httpd.conf file. In Terminal type:<br />
		<code><br />
			sudo vi /usr/local/zend/apache2/conf/httpd.conf<br />
		</code>
	</p>
<p>
		Enter your password if prompted
	</p>
</li>
<li>
<p>
		Use the up, down, left, right arrow keys to scroll down to where you see:<br />
		<code><br />
			# Virtual hosts<br />
			#Include conf/extra/httpd-vhosts.conf<br />
		</code>
	</p>
</li>
<li>
<p>
		In Terminal press &#8220;i&#8221;. This will take you into edit mode to edit the file.
	</p>
</li>
<li>
<p>
		Remove the &#8220;#&#8221; before &#8220;Include&#8221;. It should look like this now:<br />
		<code><br />
			# Virtual hosts<br />
			Include conf/extra/httpd-vhosts.conf<br />
		</code>
	</p>
</li>
<li>
<p>
		Press the escape key to exit out of edit mode. Press &#8220;:x&#8221; to save your changes.
	</p>
</li>
<li>
<p>
		Now we are going to edit our httpd-vhosts.conf file. In Terminal type:<br />
		<code><br />
			sudo vi /usr/local/zend/apache2/conf/extra/httpd-vhosts.conf<br />
		</code>
	</p>
<p>
		Enter your password when prompted
	</p>
</li>
<li>
<p>
		In Terminal press &#8220;i&#8221; to go into edit mode.
	</p>
</li>
<li>
<p>
		Use the up, down, left, right arrow keys to scroll down to where you see:<br />
		<code><br />
			NameVirtualHost *:10088<br />
		</code>
	</p>
<p>
		In the previous tutorial we change the port to 80. So now we have to change this line to read:<br />
		<code><br />
			NameVirtualHost *:80<br />
		</code>
	</p>
</li>
<li>
<p>
		Let&#8217;s say you want to have a local virtual host for http://www.super-awesome.local that needs to be pointed at the /Users/YOUR_USERNAME/Sites/super-awesome directory. We need to add the following to the httpd-vhosts.conf file:<br />
		<code><br />
			&lt;VirtualHost *:80&gt;<br />
			&nbsp;&nbsp;&nbsp;&nbsp;DocumentRoot "/Users/YOUR_USERNAME/Sites/super-awesome"<br />
			&nbsp;&nbsp;&nbsp;&nbsp;ServerName www.super-awesome.local<br />
			&nbsp;&nbsp;&nbsp;&nbsp;ServerAlias super-awesome.local<br />
			&lt;/VirtualHost&gt;<br />
		</code>
	</p>
<p>
		* Note: .local is just what I picked. You can change that to .dev or .blah or whatever you like. Try to stay away from common domain extensions like .com or .net. And, yes, you can end it with more than one extension like .foo.bar
	</p>
</li>
<li>
<p>
		Press the escape key to exit out of edit mode. Press &#8220;:x&#8221; to save your changes.
	</p>
</li>
<li>
<p>
		It&#8217;s probably a good idea to make sure we didn&#8217;t mess up syntax or spelling. In Terminal type:<br />
		<code><br />
			sudo apachectl configtest<br />
			sudo apachectl graceful<br />
		</code>
	</p>
<p>
		Enter your password if prompted
	</p>
<p>
		If there are any errors they will be displayed to you. Repeat steps 10 and 11 as many times as needed.
	</p>
</li>
<li>
<p>
		Let&#8217;s go ahead and restart Zend Server so it can get the changes. In Terminal type:<br />
		<code><br />
			sudo /usr/local/zend/bin/zendctl.sh restart<br />
		</code>
	</p>
<p>
		Enter your password if prompted
	</p>
</li>
<li>
<p>
		Browse to either http://www.super-awesome.local or http://super-awesome.local and your site should display
	</p>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2011/07/setting-up-virtual-hosts-in-zend-server-ce-on-os-x/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Installing Zend Server CE on OS X: A Guide For the Terminal Timid</title>
		<link>http://www.witheringtree.com/2011/07/installing-zend-server-ce-on-os-x-a-guide-for-the-terminal-timid/</link>
		<comments>http://www.witheringtree.com/2011/07/installing-zend-server-ce-on-os-x-a-guide-for-the-terminal-timid/#comments</comments>
		<pubDate>Sat, 16 Jul 2011 17:29:56 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Tips/Tricks]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=921</guid>
		<description><![CDATA[I use MAMP Pro both at home and at work for development. It quick, it&#8217;s easy and I really don&#8217;t have to fiddle with it a lot after it is set up. It&#8217;s perfect for me. At work we have a project to be built with Codeigniter sitting on a Linux machine but we wanted &#8230; <a href="http://www.witheringtree.com/2011/07/installing-zend-server-ce-on-os-x-a-guide-for-the-terminal-timid/" title="Continue reading">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
	I use <a href="http://mamp.info/" title="MAMP Pro" target="_blank">MAMP Pro</a> both at home and at work for development. It quick, it&#8217;s easy and I really don&#8217;t have to fiddle with it a lot after it is set up. It&#8217;s perfect for me.
</p>
<p>
	At work we have a project to be built with <a href="http://www.codeigniter.com/" title="Codeigniter" target="_blank">Codeigniter</a> sitting on a Linux machine but we wanted to use Microsoft SQL Server on a different machine as the database. Turns out, it&#8217;s not a simple as changing the database type in Codeigniter to &#8220;mssql&#8221; to get it up and running. If this is all you do, you get the dreaded white screen. You need a PHP extension to do it. Problem is, Microsoft only makes this PHP extension for Windows. There are a lot of tutorials out there on how to build the extension yourself on Mac or Linux machine (<a href="http://www.dotvoid.com/2010/01/adding-support-for-ms-sql-server-to-php-in-linux/" target="_blank">this site for example</a>), but none seemed to work for me.
</p>
<p>
	Instead of setting up a Windows virtual machine and being forced into developing that way, I decided to install Zend Server CE. Zend comes with a MSSQL extension, it just needs to be enabled.
</p>
<p>
	This tutorial does include Terminal work. I am going to walk through step-by-step, so even if you are not comfortable with Terminal, you will be up and running with Zend Server CE in no time. The only requirement is you are running an Intel Mac OS X.
</p>
<p><span id="more-921"></span></p>
<ol>
<li>
<p>
			<a href="http://www.zend.com/en/products/server-ce/index" title="Zend Server CE" target="_blank">Download Zend Server CE</a>. CE (Community Edition) is free.
		</p>
</li>
<li>
<p>
			Install Zend Server CE like you would any other application. You can optionally drop/drop Zend Controller.app into your applications directory if you want.
		</p>
</li>
<p>
			Once installed, in your applications directory, open ZendServer.app. This will open a browser window. Go through the three steps. Congratulations! You have Zend Server CE set up and running. But we aren&#8217;t done yet.
		</p>
<p>
			By default, the root folder of your Zend Server is at /usr/local/zend/htdocs. Since /usr is a hidden directory, it&#8217;s not easily accessible.
		</p>
<p>
			But first&#8230;
		</p>
</li>
<li>
<p>
			Open Terminal. Terminal can be found at /Applications/Utilities/Terminal.app
		</p>
<p>
			You can also open it from Spotlight by typing &#8220;Terminal&#8221;
		</p>
</li>
<li>
<p>
			OS X comes with Apache already installed. We don&#8217;t want to use that version. We want to use the Zend Server version.
		</p>
<p>
			In Terminal type:<br />
			<code><br />
				sudo /usr/local/zend/bin/zendctl.sh stop<br />
			</code><br />
			To stop Zend Server. Then type:<br />
			<code><br />
			sudo apachectl stop<br />
			</code></p>
<p>
			Enter your password if prompted
		</p>
</li>
<li>
<p>
			We need to move apachectl to a safe place, such as your home directory. In Terminal type:<br />
			<code><br />
				cd /usr/sbin/<br />
				sudo mv apachectl /Users/YOUR_USERNAME/<br />
			</code>
		</p>
</li>
<li>
<p>
			Then create a symbolic link to Zend Server&#8217;s apachectl. In Terminal type:<br />
			<code><br />
				sudo ln -s /usr/local/zend/apache2/bin/apachectl ./<br />
			</code>
		</p>
</li>
<li>
<p>
			Start Zend Server&#8217;s Apache. In Terminal type:<br />
			<code><br />
				sudo apachectl start<br />
			</code>
		</p>
<p>
			You should then see:<br ><br />
			<code><br />
				/usr/sbin/apachectl start [OK]<br />
			</code>
		</p>
</li>
<li>
<p>
			If you go to http://localhost/ in your browser, you will either get a forbidden or a 404 message. We&#8217;ll change that next.
		</p>
</li>
<li>
<p>
			Zend Studio&#8217;s Apache comes preconfigured to use port 10088. Let&#8217;s change this to port 80 like the default Apache port uses.
		</p>
<p>
			Now we are getting into <a href="http://en.wikipedia.org/wiki/Vi" target="_blank">vi</a> editing. I think this scares a lot of people. But don&#8217;t worry. It&#8217;s very simple.
		</p>
<p>
			We are going to edit our httpd.conf file. In Terminal type:<br />
			<code><br />
				sudo vi /usr/local/zend/apache2/conf/httpd.conf<br />
			</code>
		</p>
<p>
			Enter your password when prompted
		</p>
</li>
<li>
<p>
			You are in vi edit mode so you won&#8217;t be able to type in Terminal like you normally would. Typing only gives you the the OS X bump sound. That&#8217;s normal. You can use the up, down, left, right arrow keys.
		</p>
<p>
			Look for the line that says &#8220;Listen 10088&#8243;
		</p>
<p>
			In Terminal, type &#8220;i&#8221; to go into edit mode to start editing the file. At the bottom of the Terminal window it will say &#8220;&#8211; INSERT &#8211;&#8221; to notify you that you are editing the file.
		</p>
</li>
<li>
<p>
			With your blinker over the &#8220;L&#8221; on &#8220;Listen&#8221;, type &#8220;#&#8221; to comment out that line
		</p>
<p>
			Use the down arrow to go to the next line.
		</p>
<p>
			Type:<br />
			<code><br />
				Listen 80<br />
			</code>
		</p>
</li>
<li>
<p>
			Since we are already editing this file, we will go ahead and change our root directory since, as I mentioned earlier, the /usr directory is a hidden directory.
		</p>
<p>
			Use the down arrow to scroll down to where it says<br />
			<code><br />
				DocumentRoot "/usr/local/zend/apache2/htdocs"<br />
			</code>
		</p>
<p>
			With your blinker over the &#8220;D&#8221; on &#8220;DocumentRoot&#8221;, type &#8220;#&#8221; to comment out that line
		</p>
<p>
			Use the down arrow to go to the next line.
		</p>
<p>
			Type:<br />
			<code><br />
				DocumentRoot "/Users/YOUR_USERNAME/Sites"<br />
			</code>
		</p>
<p>
			This is the default web root for OS X sites. This is a pretty good place to put out root as well.
		</p>
</li>
<li>
<p>
			Use the down arrow again to scroll down to where it says<br />
			<code><br />
				&lt;Directory "/usr/local/zend/apache2/htdocs"&gt;<br />
			</code>
		</p>
<p>
			With your blinker over the &#8220;&lt;&#8221;, type &#8220;#&#8221; to comment out that line
		</p>
<p>
			Use the down arrow to go to the next line.
		</p>
<p>
			Type:<br />
			<code><br />
				&lt;Directory "/Users/YOUR_USERNAME/Sites"&gt;<br />
			</code>
	</li>
<li>
<p>
			We are done editing this file. Now we need to save it. In Terminal, hit the escape key to edit out of editing mode. The &#8220;&#8211; INSERT &#8211;&#8221; at the bottom will go away.
		</p>
<p>
			In Terminal again, type &#8220;:x&#8221;. This exits vi mode and saves what you changed
		</p>
</li>
<li>
<p>
			Restart apachectl type typing:<br />
			<code><br />
				sudo apachectl restart<br />
			</code>
		</p>
<p>
			Enter your password when prompted
		</p>
</li>
<li>
<p>			If you go to http://localhost/ in your browser, you will see the default Mac OS X homepage now.
		</p>
</li>
<li>
<p>
			To configure Zend Framework, type:<br />
			<code><br />
				sudo ln -s /usr/local/zend/share/ZendFramework/bin/zf.sh ./zf<br />
			</code>
	</li>
<li>
<p>
			To Configure Pear, type<br />
			<code><br />
				sudo ln -s /usr/local/zend/bin/pear ./<br />
				sudo pear upgrade pear<br />
			</code>
		</p>
</li>
<li>
<p>
			Now we have to configure MySQL. In terminal type:<br />
			<code><br />
				sudo ln -s /usr/local/zend/mysql/bin/mysql ./<br />
				sudo ln -s /usr/local/zend/mysql/bin/mysqladmin ./<br />
			</code>
		</p>
</li>
<li>
<p>
			We have to edit some settings in my.cnf for MySQL, so we go back to vi. In Terminal, type:<br />
			<code><br />
				sudo vi /usr/local/zend/mysql/data/my.cnf<br />
			</code>
		</p>
<p>
			To edit the file, it is similar to what you did in step 10.
		</p>
<p>
			Use the down arrow to scroll down to where it says:<br />
			<code><br />
				socket = /usr/local/zend/mysql/tmp/mysql.sock<br />
			</code>
		</p>
<p>
			With your blinker over the &#8220;s&#8221; on &#8220;socket&#8221;, type &#8220;#&#8221; to comment out that line
		</p>
<p>
			Use the down arrow to go to the next line.
		</p>
<p>
			Type:<br />
			<code><br />
				socket = /tmp/mysql.sock<br />
			</code>
		</p>
</li>
<li>
<p>
			By default, the password that comes with Zend Server is blank. You can change this by removing the &#8220;#&#8221; next to &#8220;password&#8221; and then changing &#8220;you_password&#8221; to whatever you want. Make sure you remember what the password is though.
		</p>
</li>
<li>
<p>
			To save the file, it is similar to what you did in step 14.
		</p>
</li>
<li>
<p>
			Configure phpMyAdmin. Since we changed the web root for Apache, we will have to create a Directory entry and Alias for phpMyAdmin, since it exists somewhere else. To edit the httpd.conf file again, in Terminal type:<br />
			<code><br />
				sudo vi /usr/local/zend/apache2/conf/httpd.conf<br />
			</code>
		</p>
<p>
			Enter your password when prompted
		</p>
</li>
<li>
<p>
			To start editing the file, use similar steps from step 10.
		</p>
<p>
			Somewhere in the file (I put it at the very end), type:<br />
			<code><br />
				Alias /phpMyAdmin /usr/local/zend/share/phpmyadmin<br />
				&lt;Directory "/usr/local/zend/share/phpmyadmin"&gt;<br />
					&nbsp;&nbsp;&nbsp;&nbsp;Options Indexes FollowSymLinks<br />
					&nbsp;&nbsp;&nbsp;&nbsp;AllowOverride All<br />
					&nbsp;&nbsp;&nbsp;&nbsp;Order allow,deny<br />
					&nbsp;&nbsp;&nbsp;&nbsp;Allow from all<br />
				&lt;/Directory&gt;<br />
			</code>
		</p>
<p>
			* Hint: Yes, you can copy/paste this if you don&#8217;t want to type it all out yourself.
		</p>
<p>
			To save the file, use similar steps from step 14.
		</p>
</li>
<li>
		Go ahead and restart Zend Server. In Terminal, type:<br />
		sudo /usr/local/zend/bin/zendctl.sh restart
	</li>
</ol>
<h3>Where do I put the file for my website(s)?</h3>
<p>
	Files will be places in /Users/YOUR_USERNAME/Sites
</p>
<p>
	Yes, of course you can create directories within that folder.
</p>
<h3>What is the URL for my site?</h3>
<p>
	The root of your site is now at <a href="http://localhost/" target="_blank">http://localhost/</a> If you have a directory within the /Users/YOUR_USERNAME/Sites directory, the URL would become http://localhost/FOLDER_NAME
</p>
<p>
	To configure Zend Server, you can get to it by going to <a href="http://localhost:10081/ZendServer/" target="_blank">http://localhost:10081/ZendServer/</a> or simply by opening ZendServer.app
</p>
<p>
	phpMyAdmin is located at <a href="http://localhost/phpMyAdmin" target="_blank">http://localhost/phpMyAdmin</a> The default username is &#8220;zend&#8221; and the password is left blank. You can also use &#8220;root&#8221; as the username. Again, with no password.
</p>
<h3>How do I start/stop/restart Zend Server?</h3>
<p>
	To start Zend Server, in Terminal type:<br />
	<code><br />
		sudo /usr/local/zend/bin/zendctl.sh start<br />
	</code>
</p>
<p>
	To stop Zend Server, in Terminal type:<br />
	<code><br />
		sudo /usr/local/zend/bin/zendctl.sh stop<br />
	</code>
</p>
<p>
	To restart Zend Server, in Terminal type:<br />
	<code><br />
		sudo /usr/local/zend/bin/zendctl.sh restart<br />
	</code>
</p>
<h3>Uninstalling Zend Server</h3>
<ol>
<li>
<p>
			Open Terminal
		</p>
</li>
<li>
<p>
			Enter<br />
			<code><br />
				sudo /usr/local/zend/bin/uninstall.sh<br />
			</code>
		</p>
<p>
			This will:</p>
<ol>
<li>Stop all Zend Server processes</li>
<li>Delete all Zend Server installed files</li>
<li>Remove the ZendServer.app from /Applications</li>
<li>Remove Zend users</li>
</ol>
</li>
<li>
<p>
			It will ask for your password. Enter your password
		</p>
</li>
<li>
<p>
			It will ask you if you are sure you want to remove Zend Server. Type &#8220;yes&#8221; (without the double quotes)
		</p>
</li>
<li>
<p>
			It tells you it will a couple directories, including your MySQL databases. Type &#8220;cont&#8221; (without the double quotes) to continue
		</p>
</li>
<li>
<p>
			In your applications directory, drag Zend Controller.app to the trash (if it is installed)
		</p>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2011/07/installing-zend-server-ce-on-os-x-a-guide-for-the-terminal-timid/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Sending email in Codeigniter with mail protocol</title>
		<link>http://www.witheringtree.com/2011/02/sending-email-in-codeigniter-with-mail-protocol/</link>
		<comments>http://www.witheringtree.com/2011/02/sending-email-in-codeigniter-with-mail-protocol/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 02:55:17 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips/Tricks]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=901</guid>
		<description><![CDATA[At work the other day I had to use the Email library in Codeigniter for the first time. The Email library is actually pretty great. Simple, yet powerful. The emails that needed to be sent out needed to bcc about 20 or more different people. On my local machine I built out all of the &#8230; <a href="http://www.witheringtree.com/2011/02/sending-email-in-codeigniter-with-mail-protocol/" title="Continue reading">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>At work the other day I had to use the Email library in Codeigniter for the first time. The Email library is actually pretty great. Simple, yet powerful.</p>
<p>The emails that needed to be sent out needed to bcc about 20 or more different people. On my local machine I built out all of the code. I was using the sendmail protocol. Everything worked perfectly, even though I only used the &#8220;bcc&#8221; function instead of the &#8220;to&#8221; function.</p>
<p>Once I uploaded the files to the server, I found out I couldn&#8217;t use the sendmail protocol. I had to use the mail protocol instead. That&#8217;s when I started getting errors. When using the sendmail protocol, it&#8217;s perfectly happy being sent an array of &#8220;bcc&#8221; emails without a &#8220;to&#8221; email address. However, the mail protocol needed a &#8220;to&#8221; email address in order to work. So I ended up using the &#8220;from&#8221; email as the &#8220;to&#8221; email also and then passing the array of &#8220;bcc&#8221; emails like i was before.</p>
<p>Hopefully this helps someone else.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2011/02/sending-email-in-codeigniter-with-mail-protocol/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Codeigniter Form Library</title>
		<link>http://www.witheringtree.com/2010/12/codeigniter-form-library/</link>
		<comments>http://www.witheringtree.com/2010/12/codeigniter-form-library/#comments</comments>
		<pubDate>Wed, 15 Dec 2010 04:09:28 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=879</guid>
		<description><![CDATA[I&#8217;ve been working on a library for Codeigniter that allows you to add a dynamic form anywhere on the page using the database to populate form information such as order of the fields, values of one or many radio, checkbox, and select options. You are even able to apply validation to individual elements. Once I &#8230; <a href="http://www.witheringtree.com/2010/12/codeigniter-form-library/" title="Continue reading">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a library for Codeigniter that allows you to add a dynamic form anywhere on the page using the database to populate form information such as order of the fields, values of one or many radio, checkbox, and select options. You are even able to apply validation to individual elements.</p>
<p>Once I am happy with everything, I will go back in and make it work with AJAX for form validation as well as submitting.</p>
<p>After that, I will turn it into PyroCMS, ExpressionEngine, and MojoMotor modules when I am happy with it all.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2010/12/codeigniter-form-library/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>First Open Source Project</title>
		<link>http://www.witheringtree.com/2010/10/first-open-source-project/</link>
		<comments>http://www.witheringtree.com/2010/10/first-open-source-project/#comments</comments>
		<pubDate>Thu, 07 Oct 2010 02:34:16 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Self]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=789</guid>
		<description><![CDATA[I just signed up for an account with Bitbucket and created my first project. I am going to be creating an open source bug tracker built on Codeigniter 2. I am going to model it based on JIRA which is a JSP bug tracker, but I have a few more plans for it. It&#8217;s just &#8230; <a href="http://www.witheringtree.com/2010/10/first-open-source-project/" title="Continue reading">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just signed up for an account with <a href="http://bitbucket.org/">Bitbucket</a> and created my first project. I am going to be creating an open source bug tracker built on <a href="http://www.codeigniter.com/">Codeigniter</a> 2. I am going to model it based on <a href="http://www.atlassian.com/software/jira/">JIRA</a> which is a JSP bug tracker, but I have a few more plans for it. It&#8217;s just started on it and there isn&#8217;t much to see just yet. Just give me time. I am using <a href="http://jasonfharris.com/machg/">MacHG</a> to do all of my Mercurial commits.</p>
<p>I am also gearing up towards working on an open source CMS based on Codeigniter named <a href="http://combustioncms.com/">Combustion CMS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2010/10/first-open-source-project/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How To Resolve MySQL Not Starting In MAMP</title>
		<link>http://www.witheringtree.com/2010/05/how-to-resolve-mysql-not-starting-in-mamp/</link>
		<comments>http://www.witheringtree.com/2010/05/how-to-resolve-mysql-not-starting-in-mamp/#comments</comments>
		<pubDate>Tue, 25 May 2010 03:56:46 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Apple Software]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tips/Tricks]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=769</guid>
		<description><![CDATA[I use MAMP daily. I love MAMP. I recently discovered how truly awesome MAMP Pro is too. But that&#8217;s a story for another time. I recently upgraded from MAMP 1.8.4 to 1.9. When I got MAMP 1.9 installed I started the servers. Apache came up but MySQL didn&#8217;t want to. I tried shutting down both &#8230; <a href="http://www.witheringtree.com/2010/05/how-to-resolve-mysql-not-starting-in-mamp/" title="Continue reading">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I use MAMP daily. I love MAMP. I recently discovered how truly awesome MAMP Pro is too. But that&#8217;s a story for another time. I recently upgraded from MAMP 1.8.4 to 1.9. When I got MAMP 1.9 installed I started the servers. Apache came up but MySQL didn&#8217;t want to. I tried shutting down both servers and starting it back up again, which didn&#8217;t work.</p>
<p>Thankfully, there is a pretty simple fix. To begin with, make sure MAMP is shut down. Next, open Terminal. To open Terminal either open Spotlight (Cmd+Space) and type &#8220;terminal&#8221; or you can find Terminal in the /Applications/Utilities/ folder.</p>
<p>Once you get Terminal opened, type the following:</p>

<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;">ps aux | grep mysql 
lsof <span style="color: #000000;">-</span>i 
killall <span style="color: #000000;">-</span><span style="color: #000000;">9</span> mysqld</pre></div></div>

<p>That&#8217;s it. Start up MAMP and MySQL will come back up just like normal. Another option would be to simply change the port number MySQL is using in MAMP. Restarting your computer may work too but I did&#8217;t try that.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2010/05/how-to-resolve-mysql-not-starting-in-mamp/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>.htaccess vs. MAMP</title>
		<link>http://www.witheringtree.com/2010/03/htaccess-vs-mamp/</link>
		<comments>http://www.witheringtree.com/2010/03/htaccess-vs-mamp/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 05:13:58 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Website]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Tips/Tricks]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=724</guid>
		<description><![CDATA[This took me three days to figure out so hopefully this saves someone else a little bit of time. The most common use of .htaccess files is removing file extensions, such as index.php, from a website URL. They are much ore powerful than that though. I&#8217;m not going to go into the details about what &#8230; <a href="http://www.witheringtree.com/2010/03/htaccess-vs-mamp/" title="Continue reading">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This took me three days to figure out so hopefully this saves someone else a little bit of time.</p>
<p>The most common use of .htaccess files is removing file extensions, such as <em>index.php</em>, from a website URL. They are much ore powerful than that though. I&#8217;m not going to go into the details about what .htaccess files can do, shouldn&#8217;t be used for, best practices, or anything else like that. I&#8217;m going to show you how to get .htaccess files set up and working with MAMP.</p>
<p><img class="size-full wp-image-726 alignleft" title="MAMP" src="http://www.witheringtree.com/wp-content/uploads/2010/03/mamp_logo.png" alt="" width="80" height="80" />The only requirements are that you have a Mac (that&#8217;s the first &#8216;M&#8217; in MAMP) and the <a href="http://www.mamp.info" target="_blank">MAMP software</a> already installed. I am using the latest version. MAMP will install everything else you need (Apache, MySQL, and PHP which is &#8216;AMP&#8217; in MAMP) to get up and running so you can start making your own sites locally.</p>
<p>First and foremost, the location of your website files in MAMP need to go in <em>/Applications/MAMP/htdocs/</em> That may sound like common sense but that&#8217;s what took the longest for me to figure out. I had my files in <em>/Applications/MAMP/bin/mamp/</em> which is where all of the files for the start page is located. I just made a folder inside there and was going to the site at http://localhost:8888/MAMP/<em>myfolder</em> No matter what I did, the .htaccess file would not work at all from within that directory. So make sure your websites files are in <em>/Applications/MAMP/htdocs/</em> or a folder within.</p>
<p><img class="size-full wp-image-725 alignleft" title="Hidden Files Widget" src="http://www.witheringtree.com/wp-content/uploads/2010/03/hidden_files_widget.png" alt="" width="100" height="67" />The next thing you need to know is &#8216;htaccess&#8217; isn&#8217;t the file extension and there isn&#8217;t a file name on the file. The dot at the front typically means it is a hidden file on Unix based operating systems (which the Mac is). So you will need to show the hidden files on your machine. There are a few ways to do this. One of the easiest ways is to use a Dashboard widget. <a href="http://www.apple.com/downloads/dashboard/developer/hiddenfiles.html" target="_blank">Hidden Files Widget</a> is a great widget for this. If the hidden files are hidden, the button will say &#8216;Show&#8217;. If the hidden files are visible, the button will say &#8216;Hide&#8217;. It can&#8217;t get any more simple that that. Install the widget then click the &#8216;Show&#8217; button. Sometimes the desktop icons won&#8217;t come back automatically. If they don&#8217;t come back after a minute, click on the Finder icon in the dock and they should come back. Now, go to wherever your website files are located. If there is a .htaccess file in the folder, skip the next paragraph. If it is not there, read the next paragraph.</p>
<p>Here is the catch. It&#8217;s tough to create a .htaccess file because the Mac thinks &#8216;htaccess&#8217; is the file extension but you didn&#8217;t give the file a name. So it won&#8217;t just let you do it. WordPress creates a .htaccess file for you when you set up a blog locally. I believe Drupal does the same thing but I&#8217;m not 100% positive on that. Other applications possibly do as well. If you aren&#8217;t installing a CMS like that, you can always <a href="http://www.htaccesseditor.com/" target="_blank">create a custom one and download it</a>. Below is a very basic example of a .htaccess file that I typically use. Once you have a .htaccess file, put it in the root of where your website will live.</p>
<p>The .htaccess file can be opened with TextEdit. You can open it with Dreamweaver or almost anything you want. Here is an example of a typical .htaccess file</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># BEGIN My_Website
</span><span style="color: #339933;">&lt;</span>IfModule mod_rewrite<span style="color: #339933;">.</span>c<span style="color: #339933;">&gt;</span>
	RewriteEngine On
	<span style="color: #666666; font-style: italic;">#RewriteBase /
</span>	RewriteBase <span style="color: #339933;">/</span>mywebsite<span style="color: #339933;">/</span>
	RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>REQUEST_FILENAME<span style="color: #009900;">&#125;</span> <span style="color: #339933;">!-</span>f
	RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>REQUEST_FILENAME<span style="color: #009900;">&#125;</span> <span style="color: #339933;">!-</span>d
	RewriteRule <span style="color: #339933;">.</span> <span style="color: #339933;">/</span>index<span style="color: #339933;">.</span>php <span style="color: #009900;">&#91;</span>L<span style="color: #009900;">&#93;</span>
	<span style="color: #666666; font-style: italic;">#RewriteRule ^(.*)$ /index.php/$1 [L]
</span><span style="color: #339933;">&lt;/</span>IfModule<span style="color: #339933;">&gt;</span>
<span style="color: #666666; font-style: italic;"># END My_Website</span></pre></td></tr></table></div>

<p>The hash marks (#) are comments. I&#8217;ll talk a little about the second and third commenta in a second.</p>
<p>If you are developing a site locally, your files may not be in the root of the <em>/Applications/MAMP/htdocs/</em> folder since you may be working on more than one website. That is what the <em>RewriteBase</em> is for. It specifies where the root of your website is in accordance with the root of the domain or local root. In this example, my website and it&#8217;s files are in a folder called <em>mywebsite</em> which is inside my <em>/Applications/MAMP/htdocs/</em> folder. Since <em>/Applications/MAMP/htdocs/</em> is my root folder, I don&#8217;t have to put that in the path. I just have to put the path from the root folder. If you notice, on the line above that (line 4), I have commented out that line with a hash. When you upload the files to your website, uncomment this line (line 4) and comment out the line after it (line 5). That way the .htaccess file works when you get it on the actual site. If you are not uploading the files to the root of your website, set the path accordingly.</p>
<p>The third comment (line 9) is a variation of the line above it (line 8). Both work pretty much the same. You don&#8217;t have to have the first and last comment lines. You can delete them and it won&#8217;t effect anything.</p>
<p>That is literally all I had to do to get the site working. I saw sites that wanted me to edit httpd.conf files and php.ini files and all kinds of files under the sun. I didn&#8217;t have to though. If you do need to mess with those files, there are a couple pretty good walkthroughs to help you out <a href="http://objectmix.com/apache/675017-htaccess-files-mac-mamp.html" target="_blank">here</a> and <a href="http://rexselin.wordpress.com/2006/07/28/making-mod-rewrite-and-htaccess-work-on-mac-os-x/" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2010/03/htaccess-vs-mamp/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

