<?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; CodeIgniter</title>
	<atom:link href="http://www.witheringtree.com/tag/codeigniter/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>Sat, 05 May 2012 15:15:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Overloading Codeigniter DB Driver</title>
		<link>http://www.witheringtree.com/2012/02/overloading-codeigniter-db-driver/</link>
		<comments>http://www.witheringtree.com/2012/02/overloading-codeigniter-db-driver/#comments</comments>
		<pubDate>Sun, 26 Feb 2012 16:53:03 +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[Tips/Tricks]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=972</guid>
		<description><![CDATA[Working with Microsoft SQL Server and PHP isn&#8217;t always the easiest thing to do. There are always like quarks you have to work around and even big problems that have to be fixed before anything else can be done. One of the most annoying things I have found is that MSSQL doesn&#8217;t have an offset &#8230; <a href="http://www.witheringtree.com/2012/02/overloading-codeigniter-db-driver/" title="Continue reading">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Working with Microsoft SQL Server and PHP isn&#8217;t always the easiest thing to do. There are always like quarks you have to work around and even big problems that have to be fixed before anything else can be done.</p>
<p>One of the most annoying things I have found is that MSSQL doesn&#8217;t have an offset like MySQL does. Offsets are great for pagination. If you have 1000 records and you want to pull 200 records at at time, you would limit the number of records to 200 (TOP 200). But how do you get to page two? That&#8217;s where offset comes in. Let&#8217;s says you want to get the top X records, but offset by Y records. Without offset, the only decent way I could think of to do pagination was to pull the top 400 and in the PHP code I split off the first 200 records that I don&#8217;t need. That gets pretty ugly if there are 10k records and you are displaying 10 records at a time. By the last page, your query is taking way to long to return results when you aren&#8217;t using 99% of them.</p>
<p>All that being said, I am working on a project built with Codeigniter that connects to a MSSQL database. Codeigniter has some pretty good DB libraries so most things work just fine. My two big problems are offset and batch insert and batch update (more on batch in a later post). We don&#8217;t want to go into the Codeigniter system directory and start changing things as we see fit. If we dod that, we can never update Codeigniter at a later date. The answer is to overload, or extend, the Codeigniter database driver. What we have to do is extend a function in the system/core/Loader.php file. To do this, in application/core/ create a file named MY_Loader.php. Just to reiterate, this file goes in application/core/ NOT application/libraries/ If you have changed the subclass_prefix config value to something other than MY_ then you will need to rename the file accordingly. Next, copy/paste the code below into the file you just created.</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_Loader <span style="color: #000000; font-weight: bold;">extends</span> CI_Loader <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> database<span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">,</span> <span style="color: #000088;">$active_record</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Grab the super object</span>
		<span style="color: #000088;">$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>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Do we even need to load the database class?</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">class_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'CI_DB'</span><span style="color: #009900;">&#41;</span> AND <span style="color: #000088;">$return</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">FALSE</span> AND <span style="color: #000088;">$active_record</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">NULL</span> AND <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #009900;">&#41;</span> AND <span style="color: #990000;">is_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #009900;">&#41;</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>
&nbsp;
		<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>BASEPATH<span style="color: #339933;">.</span><span style="color: #0000ff;">'database/DB.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> DB<span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #339933;">,</span> <span style="color: #000088;">$active_record</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Load extended DB driver</span>
		<span style="color: #000088;">$custom_db_driver</span> <span style="color: #339933;">=</span> config_item<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'subclass_prefix'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'DB_'</span><span style="color: #339933;">.</span><span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbdriver</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_driver'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$custom_db_driver_file</span> <span style="color: #339933;">=</span> APPPATH<span style="color: #339933;">.</span><span style="color: #0000ff;">'core/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$custom_db_driver</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.php'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$custom_db_driver_file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$custom_db_driver_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000088;">$custom_db_driver</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">get_object_vars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Return DB instance</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$return</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$db</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Initialize the db variable. Needed to prevent reference errors with some configurations</span>
		<span style="color: #000088;">$CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span> <span style="color: #339933;">=&amp;</span> <span style="color: #000088;">$db</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The above code is pretty much the same thing found in system/core/Loader.php with some changes to make it look in application/core/ for your extensions to the database drivers. If there aren&#8217;t any database extensions, no big deal. It will continue on like normal.</p>
<p>So the next thing we have to do is create a file named MY_DB_mssql_driver.php in application/core/ Again, this file goes in application/core/ NOT application/libraries/ and if you have changed the subclass_prefix config value to something other than MY_ then you will need to rename the file accordingly. In my case, I am extending the MSSQL database driver so my file is named MY_DB_mssql_driver.php. If you are extending the MySQL driver, then you would name it MY_DB_mysql_driver.php. Next, copy/paste the following code into the MY_DB_mssql_driver.php file you just created</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_DB_mssql_driver <span style="color: #000000; font-weight: bold;">extends</span> CI_DB_mssql_driver <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Limit string
	 *
	 * Generates a platform-specific LIMIT clause
	 *
	 * @param	string	the sql query string
	 * @param	integer	the number of rows to limit the query to
	 * @param	integer	the offset value
	 * @return	string
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> _limit<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span> <span style="color: #000088;">$limit</span><span style="color: #339933;">,</span> <span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$limit</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">return</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/(^\SELECT (DISTINCT)?)/i'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'\\1 TOP '</span><span style="color: #339933;">.</span><span style="color: #000088;">$i</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ar_orderby</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$ordeR_by</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ORDER BY &quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$ordeR_by</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">', '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ar_orderby</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ar_order</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$ordeR_by</span> <span style="color: #339933;">.=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ar_order</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'desc'</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">' DESC'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">' ASC'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/(\\'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$ordeR_by</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'\n?)/i'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/(^\SELECT (DISTINCT)?)/i'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'\\1 row_number() OVER ('</span><span style="color: #339933;">.</span><span style="color: #000088;">$ordeR_by</span><span style="color: #339933;">.</span><span style="color: #0000ff;">') AS rownum, '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;SELECT * <span style="color: #000099; font-weight: bold;">\n</span>FROM (<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$sql</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;) AS A <span style="color: #000099; font-weight: bold;">\n</span>WHERE A.rownum BETWEEN (&quot;</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;) AND (&quot;</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$limit</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Query must have an order_by clause in order to be offset.'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The above code is a direct copy/paste from the code <a href="http://codeigniter.com/forums/member/88927/" target="_blank">Kyle Johnson</a> on is <a href="http://codeigniter.com/forums/viewthread/160626/#959597" target="_blank">Codeigniter forum post</a>. All it does is check if an offset is being passed. If there is, then it builds a subquery to create the offset. If the offset is not defined or is 0, then it does the normal function does.</p>
<p>The only thing you have to do now is run your application. There shouldn&#8217;t be any additional changes to any libraries or to your SQL calls.</p>
<p>Again, the files for this post have been committed to <a href="https://github.com/dfreerksen/ci-overload-db" target="_blank">Github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2012/02/overloading-codeigniter-db-driver/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>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>Mercurial .hgignore file</title>
		<link>http://www.witheringtree.com/2011/04/mercurial-hgignore-file/</link>
		<comments>http://www.witheringtree.com/2011/04/mercurial-hgignore-file/#comments</comments>
		<pubDate>Sun, 03 Apr 2011 16:09:07 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tips/Tricks]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=913</guid>
		<description><![CDATA[If you are using Mercurial, there is this handy file in your repository root called .hgignore. This is a file that keeps track of all of the files that should not be tracked by Mercurial. For example, log files or cache files should not be committed to repositories. I do a lot of work with &#8230; <a href="http://www.witheringtree.com/2011/04/mercurial-hgignore-file/" title="Continue reading">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you are using Mercurial, there is this handy file in your repository root called .hgignore. This is a file that keeps track of all of the files that should not be tracked by Mercurial. For example, log files or cache files should not be committed to repositories.</p>
<p>I do a lot of work with PHP, Codeigniter, and Eclipse on the Mac. This is what my .igignore file looks like:</p>
<p>application/logs/(?!index\.html|\.htaccess)<br />
application/cache/(?!index\.html|\.htaccess)<br />
syntax: glob<br />
.DS_Store<br />
*.[Bb][Aa][Kk]<br />
[Bb][Aa][Kk]<br />
*.[Cc]ache<br />
.buildpath<br />
.project<br />
.settings</p>
<p>The first two lines keep my logs and cache directories empty on commit except for the index.html and .htaccess files that are in there. .DS_Store is used by Finder. It’s similar to the desktop.ini file on Windows. The last three lines are to keep my Eclipse project files out of the repo. Everything else is files and directories that I tend to call things.</p>
<p>If you are on Windows, instead of .DS_Store you will probably need [Tt]humbs.db as well. If you are working with Microsoft Visual Studio and .Net, you are going to need a few more things. The ones I can think of off the top of my head are:</p>
<p>syntax: glob<br />
*.suo<br />
*.webinfo<br />
[Bb]in<br />
*/[Bb]in<br />
[Rr]elease<br />
*/[Rr]elease<br />
[Dd]ebug<br />
*/[Dd]ebug</p>
<p>All of this will of course change depending on the IDE, preferences, and framework you are using. This will help you get started.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2011/04/mercurial-hgignore-file/feed/</wfw:commentRss>
		<slash:comments>0</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>.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>
		<item>
		<title>Extending Template Parser</title>
		<link>http://www.witheringtree.com/2009/12/extending-template-parser/</link>
		<comments>http://www.witheringtree.com/2009/12/extending-template-parser/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 18:31:57 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=599</guid>
		<description><![CDATA[I am working on some stuff for work (yes, on the weekend) that uses the Codeigniter Template Parser class to display content with pseudo variables. I have a pseudo variable parser that allows me to call up a certain function from a certain helper file. To do this I would do something similar to this: &#8230; <a href="http://www.witheringtree.com/2009/12/extending-template-parser/" title="Continue reading">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I am working on some stuff for work (yes, on the weekend) that uses the Codeigniter Template Parser class to display content with pseudo variables. I have a pseudo variable parser that allows me to call up a certain function from a certain helper file. To do this I would do something similar to this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009900;">&#123;</span>ns<span style="color: #339933;">:</span>gallery<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'foo'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>Where &#8220;df&#8221; is the name of the helper file (minus &#8220;_helper&#8221;) that gets loaded in if it hasn&#8217;t been already, &#8220;gallery&#8221; is the name of the function, and everything inside the brackets are values that get passed to the function.</p>
<p>I also thought about doing something more like HTML tags with pseudo variables. So the above example could be:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009900;">&#123;</span>ns<span style="color: #339933;">:</span>gallery name<span style="color: #339933;">=</span><span style="color: #0000ff;">'foo'</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>Similar concept but this way all of the attributes could be thrown into an object when it gets o the function so I can have as many or as few settings in it as I want instead of having to pass a certain number of arguments in a certain order. I would have to have default values for everything in case an attribute I needed wasn&#8217;t passed. Same idea as the way HTML tags work.</p>
<p>This is basically like creating my own pseudo HTML tags with { and } instead of &lt; and &gt;. So then I thought, why not make it a namespace tag? I would just have to replace the { and } with &lt; and &gt; and I get:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>ns<span style="color: #339933;">:</span>gallery name<span style="color: #339933;">=</span><span style="color: #0000ff;">'foo'</span> <span style="color: #339933;">/&gt;</span></pre></div></div>

<p>To do this I would so something similar to this post titled &#8216;<a href="http://stackoverflow.com/questions/1201778/parsing-custom-tags-with-php" target="_blank">Parsing Custom Tags With PHP</a>&#8216;.</p>
<p>There are advantages and disadvantages to all three. Right now I am leaning more toward the second or third options because if someone goes in after me and needs to edit the file, I think that makes more sense than the first way. Any way I go it just means extending the Codeigniter Template Parser class. Maybe I&#8217;ll do all three and release it to the Codeigniter community.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2009/12/extending-template-parser/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Route Everything, Except These Controllers</title>
		<link>http://www.witheringtree.com/2009/10/route-everything-except-these-controllers/</link>
		<comments>http://www.witheringtree.com/2009/10/route-everything-except-these-controllers/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 13:56:53 +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=404</guid>
		<description><![CDATA[I was playing with CodeIgniter routing at work. I wanted to have a catch-all route but I needed to exclude a certain controller, or controllers, from that catch-all route. As an example, I wanted to have http://www.example.com/(ANYTHING) route to the &#8220;page&#8221; controller. http://www.example.com/policies/shipping would route to the &#8220;policies&#8221; controller and then to the &#8220;ship&#8221; method. &#8230; <a href="http://www.witheringtree.com/2009/10/route-everything-except-these-controllers/" title="Continue reading">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was playing with <a title="CodeIgniter" href="http://www.codeigniter.com" target="_blank">CodeIgniter</a> routing at work. I wanted to have a catch-all route but I needed to exclude a certain controller, or controllers, from that catch-all route. As an example, I wanted to have http://www.example.com/(ANYTHING) route to the &#8220;page&#8221; controller. http://www.example.com/policies/shipping would route to the &#8220;policies&#8221; controller and then to the &#8220;ship&#8221; method. From there the &#8220;page&#8221; controller would split up all of the segments.</p>
<p>I started out with this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$route</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'policies/shipping'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;policies/ship&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$route</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'(:any)'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;page&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The &#8220;policies/ship&#8221; route would be caught by the &#8220;policies&#8221; controller and everything else would be caught by the &#8220;page&#8221; controller. Except the &#8220;page&#8221; controller was getting everything.</p>
<p>I needed to exclude certain controllers from the catch-all route. After a Google search, I came up with nothing. So I started working on it myself. Here is what I cam up with:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$route</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'policies/shipping'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;policies/ship&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$route</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'^(?!policies|controllerA|controllerB)\S*'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;page&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So far it seems to work perfectly. Hopefully this helps someone else out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2009/10/route-everything-except-these-controllers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

