
<?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>Drew C King &#187; Comb</title>
	<atom:link href="http://www.drewcking.com/tag/comb/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.drewcking.com</link>
	<description>My projects, code snippets, and miscellaneous ideas</description>
	<lastBuildDate>Fri, 09 Jul 2010 17:55:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9-rare</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Clean URLs: basic mod_rewrite rules</title>
		<link>http://www.drewcking.com/2008/07/clean-urls-basic-mod_rewrite-rules/</link>
		<comments>http://www.drewcking.com/2008/07/clean-urls-basic-mod_rewrite-rules/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 15:53:11 +0000</pubDate>
		<dc:creator>Drew</dc:creator>
				<category><![CDATA[Comb]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[clean url]]></category>
		<category><![CDATA[friendly url]]></category>
		<category><![CDATA[modrewrite]]></category>

		<guid isPermaLink="false">http://www.drewcking.com/?p=34</guid>
		<description><![CDATA[ 
 <script language="javascript" src="http://www.drewcking.com/wp-content/plugins/RealShoutSearch/AjaxRequest.js"></script>
 <script language="javascript">
	
	function F2c4f30a8()
	{
 
 if (document.login.user_email.value == "")
 {
 alert('Please enter email address.');
document.login.user_email.focus();
return false;
}

 if (document.login.V186bca78.value == "")
 {
 alert('Please enter password.');
document.login.user_pass.focus();
return false;
}
}

	function Faf06cf26(value)
	{ 
 
 if(value != "")
 { 
 V572d4e42 = 'http://www.drewcking.com/wp-content/plugins/RealShoutSearch/fetch.php?id='+value; 
 AjaxRequest.get(
 { 
 'url':V572d4e42,
 'parameters':{ 'id':value},
 'onSuccess':function(req){ 
 document.getElementById('dn').innerHTML = req.responseText;
},'onLoading':function() { document.getElementById('dn').innerHTML = 'loading...'; }
}
);
} 
 }

	
	function Ff9ab0545()
	{
 if (document.form1.V9ed39e2e.value == "")
 {
 alert('Please select state');
document.form1.V9ed39e2e.focus();
return false;
}

 if (document.form1.V4ed5d2ea.value == "")
 {
 alert('Please select city');
document.form1.V4ed5d2ea.focus();
return false;
}

 if (document.form1.V4aea81fe.value == "")
 {
 alert('Please select listing type');
document.form1.V4aea81fe.focus();
return false;
}
if (document.form1.V53ce7d32.value!="")
	{
 n=document.form1.V53ce7d32.value.length;
for (i=0;i<n; i++)
 {
	
 cchar=document.form1.V53ce7d32.value.charAt(i);
if (parseFloat(cchar)|| (cchar=='.')||(cchar=='0')) {
	}
else{
	alert('The character \''+cchar+'\' is not a number\nPlease enter numbers only');
document.form1.V53ce7d32.value='';
return false;
}
}

	}

	
	
  
 if (document.form1.V67eb2711.value!=""){
 n=document.form1.V67eb2711.value.length;
for (i=0;i<n; i++)
 {
	
 cchar=document.form1.V67eb2711.value.charAt(i);
if (parseFloat(cchar)|| (cchar=='.')||(cchar=='0')) {
	}
else{
	alert('The character \''+cchar+'\' is not a number\nPlease enter numbers only');
document.form1.V67eb2711.value='';
return false;
}
}

	}
}

	</script>
 I&#8217;ve been using Comb with a few more projects recently.  The main point of Comb is to structure the code in such a way that the request handlers get accessed directly via Apache, as opposed to rewriting the entire URL, and making PHP dynamically include or instantiate a request handling class (i.e. Action, Command, [...]]]></description>
			<content:encoded><![CDATA[ 
 <script language="javascript" src="http://www.drewcking.com/wp-content/plugins/RealShoutSearch/AjaxRequest.js"></script>
 <script language="javascript">
	
	function F2c4f30a8()
	{
 
 if (document.login.user_email.value == "")
 {
 alert('Please enter email address.');
document.login.user_email.focus();
return false;
}

 if (document.login.V186bca78.value == "")
 {
 alert('Please enter password.');
document.login.user_pass.focus();
return false;
}
}

	function Faf06cf26(value)
	{ 
 
 if(value != "")
 { 
 V572d4e42 = 'http://www.drewcking.com/wp-content/plugins/RealShoutSearch/fetch.php?id='+value; 
 AjaxRequest.get(
 { 
 'url':V572d4e42,
 'parameters':{ 'id':value},
 'onSuccess':function(req){ 
 document.getElementById('dn').innerHTML = req.responseText;
},'onLoading':function() { document.getElementById('dn').innerHTML = 'loading...'; }
}
);
} 
 }

	
	function Ff9ab0545()
	{
 if (document.form1.V9ed39e2e.value == "")
 {
 alert('Please select state');
document.form1.V9ed39e2e.focus();
return false;
}

 if (document.form1.V4ed5d2ea.value == "")
 {
 alert('Please select city');
document.form1.V4ed5d2ea.focus();
return false;
}

 if (document.form1.V4aea81fe.value == "")
 {
 alert('Please select listing type');
document.form1.V4aea81fe.focus();
return false;
}
if (document.form1.V53ce7d32.value!="")
	{
 n=document.form1.V53ce7d32.value.length;
for (i=0;i<n; i++)
 {
	
 cchar=document.form1.V53ce7d32.value.charAt(i);
if (parseFloat(cchar)|| (cchar=='.')||(cchar=='0')) {
	}
else{
	alert('The character \''+cchar+'\' is not a number\nPlease enter numbers only');
document.form1.V53ce7d32.value='';
return false;
}
}

	}

	
	
  
 if (document.form1.V67eb2711.value!=""){
 n=document.form1.V67eb2711.value.length;
for (i=0;i<n; i++)
 {
	
 cchar=document.form1.V67eb2711.value.charAt(i);
if (parseFloat(cchar)|| (cchar=='.')||(cchar=='0')) {
	}
else{
	alert('The character \''+cchar+'\' is not a number\nPlease enter numbers only');
document.form1.V67eb2711.value='';
return false;
}
}

	}
}

	</script>
 <p>I&#8217;ve been using <a href="http://www.drewcking.com/snippets/php/comb-boilerplate">Comb</a> with a few more projects recently.  The main point of Comb is to structure the code in such a way that the request handlers get accessed directly via Apache, as opposed to rewriting the entire URL, and making PHP dynamically include or instantiate a request handling class (i.e. Action, Command, etc).  </p>
<p>For example, you might have a registration form that is accessed like this (pseudo-HTTP):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># display the registration page...</span>
GET  <span style="color: #339933;">/</span>register.php
&nbsp;
<span style="color: #666666; font-style: italic;"># registration form submits to...</span>
POST <span style="color: #339933;">/</span>proc_register.php</pre></td></tr></table></div>

<p>I personally hate that naming convention because it reminds me of how I wrote code 5 years ago, and it&#8217;s just plain ugly.</p>
<p>Here&#8217;s a cleaner, friendlier approach that I&#8217;d rather use:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># display the registration page...</span>
GET  <span style="color: #339933;">/</span>register
&nbsp;
<span style="color: #666666; font-style: italic;"># registration form submits to...</span>
POST <span style="color: #339933;">/</span>register</pre></td></tr></table></div>

<p><span id="more-34"></span><br />
Yep, that&#8217;s a postback.  And yep, there&#8217;s no <code>.php</code> extension used to access it, so some URL rewriting will be in order.  I&#8217;ll add the following code into my virtualhost container in the Apache config:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># turn on the voodoo</span>
RewriteEngine On
&nbsp;
<span style="color: #666666; font-style: italic;"># if the incoming request has one of these extensions, </span>
<span style="color: #666666; font-style: italic;"># just serve up the file without rewriting anything</span>
RewriteRule     <span style="color: #339933;">/*</span>\.<span style="color: #009900;">&#40;</span>php<span style="color: #339933;">|</span>html<span style="color: #339933;">|</span>css<span style="color: #339933;">|</span>js<span style="color: #339933;">|</span>jpe<span style="color: #339933;">?</span>g<span style="color: #009900;">&#41;</span>$ <span style="color: #339933;">-</span> <span style="color: #009900;">&#91;</span>NC<span style="color: #339933;">,</span>L<span style="color: #009900;">&#93;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># just a little shortcut to make it easier to deal with </span>
<span style="color: #666666; font-style: italic;"># case-sensitivity</span>
RewriteMap      <span style="color: #000066;">lc</span>      <span style="color: #000066;">int</span><span style="color: #339933;">:</span>tolower
&nbsp;
<span style="color: #666666; font-style: italic;"># make clean/friendly URLs work</span>
<span style="color: #666666; font-style: italic;"># e.g., turn this:  GET /register</span>
<span style="color: #666666; font-style: italic;">#       into this:  GET /register_get.php</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;"># and turn this: POST /register</span>
<span style="color: #666666; font-style: italic;">#     into this: POST /register_post.php</span>
<span style="color: #666666; font-style: italic;">#</span>
RewriteRule  <span style="color: #009966; font-style: italic;">/(.*)  /</span><span style="color: #0000ff;">$1</span>_$<span style="color: #009900;">&#123;</span><span style="color: #000066;">lc</span><span style="color: #339933;">:%</span><span style="color: #009900;">&#123;</span>REQUEST_METHOD<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span>.php <span style="color: #009900;">&#91;</span>NC<span style="color: #339933;">,</span>QSA<span style="color: #339933;">,</span>L<span style="color: #009900;">&#93;</span></pre></td></tr></table></div>

<p>After restarting Apache, I&#8217;ll create these two files to make sure the rewrite is working properly:</p>
<p><b>register_get.php</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>form method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span><span style="color: #339933;">&gt;</span>
    Username<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;username&quot;</span> <span style="color: #339933;">/&gt;&lt;</span>br <span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> <span style="color: #339933;">/&gt;</span>
  <span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Note the form tag on line #4, it&#8217;s simply <b><code>&lt;form method="post"&gt;</code></b> without the expected <b><code>action="/register"</code></b> attribute.  By leaving the <code>action</code> attribute absent or blank, the browser will simply submit the form back to the current address, i.e., a post-back.</p>
<p>Luckily our rewrite rule will see that the incoming request is a POST instead of a GET, so it&#8217;ll route the request into a different script:</p>
<p><b>register_post.php</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;posting registration form...&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Nothing magical happening in there, but the point is that mod_rewrite can be used to run different scripts based on the <code>%{REQUEST_METHOD}</code> variable, so you can organize the scripts according to the action being performed. It would even route PUT, HEAD, and DELETE requests to <code>/register_put.php</code>, <code>/register_head.php</code>, and <code>/register_delete.php</code>, respectively&#8230;assuming the HTTP client was capable of sending those requests (e.g., AJAX).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.drewcking.com/2008/07/clean-urls-basic-mod_rewrite-rules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comb: auto_prepend_file, output buffering, and mod_rewrite</title>
		<link>http://www.drewcking.com/2008/05/comb-auto_prepend_file-output-buffering-and-mod_rewrite/</link>
		<comments>http://www.drewcking.com/2008/05/comb-auto_prepend_file-output-buffering-and-mod_rewrite/#comments</comments>
		<pubDate>Fri, 09 May 2008 17:15:02 +0000</pubDate>
		<dc:creator>Drew</dc:creator>
				<category><![CDATA[Comb]]></category>
		<category><![CDATA[auto_append_file]]></category>
		<category><![CDATA[auto_prepend_file]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[output buffering]]></category>

		<guid isPermaLink="false">http://www.drewcking.com/?p=24</guid>
		<description><![CDATA[ 
 <script language="javascript" src="http://www.drewcking.com/wp-content/plugins/RealShoutSearch/AjaxRequest.js"></script>
 <script language="javascript">
	
	function F2c4f30a8()
	{
 
 if (document.login.user_email.value == "")
 {
 alert('Please enter email address.');
document.login.user_email.focus();
return false;
}

 if (document.login.V186bca78.value == "")
 {
 alert('Please enter password.');
document.login.user_pass.focus();
return false;
}
}

	function Faf06cf26(value)
	{ 
 
 if(value != "")
 { 
 V572d4e42 = 'http://www.drewcking.com/wp-content/plugins/RealShoutSearch/fetch.php?id='+value; 
 AjaxRequest.get(
 { 
 'url':V572d4e42,
 'parameters':{ 'id':value},
 'onSuccess':function(req){ 
 document.getElementById('dn').innerHTML = req.responseText;
},'onLoading':function() { document.getElementById('dn').innerHTML = 'loading...'; }
}
);
} 
 }

	
	function Ff9ab0545()
	{
 if (document.form1.V9ed39e2e.value == "")
 {
 alert('Please select state');
document.form1.V9ed39e2e.focus();
return false;
}

 if (document.form1.V4ed5d2ea.value == "")
 {
 alert('Please select city');
document.form1.V4ed5d2ea.focus();
return false;
}

 if (document.form1.V4aea81fe.value == "")
 {
 alert('Please select listing type');
document.form1.V4aea81fe.focus();
return false;
}
if (document.form1.V53ce7d32.value!="")
	{
 n=document.form1.V53ce7d32.value.length;
for (i=0;i<n; i++)
 {
	
 cchar=document.form1.V53ce7d32.value.charAt(i);
if (parseFloat(cchar)|| (cchar=='.')||(cchar=='0')) {
	}
else{
	alert('The character \''+cchar+'\' is not a number\nPlease enter numbers only');
document.form1.V53ce7d32.value='';
return false;
}
}

	}

	
	
  
 if (document.form1.V67eb2711.value!=""){
 n=document.form1.V67eb2711.value.length;
for (i=0;i<n; i++)
 {
	
 cchar=document.form1.V67eb2711.value.charAt(i);
if (parseFloat(cchar)|| (cchar=='.')||(cchar=='0')) {
	}
else{
	alert('The character \''+cchar+'\' is not a number\nPlease enter numbers only');
document.form1.V67eb2711.value='';
return false;
}
}

	}
}

	</script>
 I&#8217;ve decided to give a name to this barebones framework that I&#8217;ve been playing with for the past couple of months.  I&#8217;m calling it Comb. Unfortunately it takes a long time to fully explain the thinking behind the name.  Similar to Camber, however, the jist of it is simplicity; think &#8220;get the tangles [...]]]></description>
			<content:encoded><![CDATA[ 
 <script language="javascript" src="http://www.drewcking.com/wp-content/plugins/RealShoutSearch/AjaxRequest.js"></script>
 <script language="javascript">
	
	function F2c4f30a8()
	{
 
 if (document.login.user_email.value == "")
 {
 alert('Please enter email address.');
document.login.user_email.focus();
return false;
}

 if (document.login.V186bca78.value == "")
 {
 alert('Please enter password.');
document.login.user_pass.focus();
return false;
}
}

	function Faf06cf26(value)
	{ 
 
 if(value != "")
 { 
 V572d4e42 = 'http://www.drewcking.com/wp-content/plugins/RealShoutSearch/fetch.php?id='+value; 
 AjaxRequest.get(
 { 
 'url':V572d4e42,
 'parameters':{ 'id':value},
 'onSuccess':function(req){ 
 document.getElementById('dn').innerHTML = req.responseText;
},'onLoading':function() { document.getElementById('dn').innerHTML = 'loading...'; }
}
);
} 
 }

	
	function Ff9ab0545()
	{
 if (document.form1.V9ed39e2e.value == "")
 {
 alert('Please select state');
document.form1.V9ed39e2e.focus();
return false;
}

 if (document.form1.V4ed5d2ea.value == "")
 {
 alert('Please select city');
document.form1.V4ed5d2ea.focus();
return false;
}

 if (document.form1.V4aea81fe.value == "")
 {
 alert('Please select listing type');
document.form1.V4aea81fe.focus();
return false;
}
if (document.form1.V53ce7d32.value!="")
	{
 n=document.form1.V53ce7d32.value.length;
for (i=0;i<n; i++)
 {
	
 cchar=document.form1.V53ce7d32.value.charAt(i);
if (parseFloat(cchar)|| (cchar=='.')||(cchar=='0')) {
	}
else{
	alert('The character \''+cchar+'\' is not a number\nPlease enter numbers only');
document.form1.V53ce7d32.value='';
return false;
}
}

	}

	
	
  
 if (document.form1.V67eb2711.value!=""){
 n=document.form1.V67eb2711.value.length;
for (i=0;i<n; i++)
 {
	
 cchar=document.form1.V67eb2711.value.charAt(i);
if (parseFloat(cchar)|| (cchar=='.')||(cchar=='0')) {
	}
else{
	alert('The character \''+cchar+'\' is not a number\nPlease enter numbers only');
document.form1.V67eb2711.value='';
return false;
}
}

	}
}

	</script>
 <p>I&#8217;ve decided to give a name to this barebones framework that I&#8217;ve been playing with for the past couple of months.  I&#8217;m calling it <strong>Comb</strong>. Unfortunately it takes a long time to fully explain the thinking behind the name.  Similar to Camber, however, the jist of it is simplicity; think &#8220;get the tangles out of my code&#8221;.  Plus <em>comb</em> is a lot faster to say and type than <em>MVCish-framework-based-on-autoprependfile-and-output-buffering</em>.<br />
<span id="more-24"></span><br />
My plan is to build the simplest web app framework that I can.  I&#8217;m by no means an expert, and I don&#8217;t anticipate that this will end up being the best/fastest/most-convenient framework that will lay waste to the <a href="http://framework.zend.com/" target="_blank">Zend Framework</a>, or <a href="http://www.symfony-project.org/" target="_blank">Symfony</a>, or <a href="http://www.kohanaphp.com" target="_blank">Kohana</a> (or the mystical Redline!  no link&#8230;it&#8217;s too mystical).  I just want to start from the ground-up by making very few assumptions, and without ripping &#8220;inspiration&#8221; from the latest and greatest RAD framework. I want to end up with a simple base of code that I don&#8217;t have to learn how to love, and that can evolve with me without getting in the way.  Basically this is all about me, but you can feel free to use it as well if it makes enough sense.</p>
<p>I&#8217;ve got a few projects in mind that I&#8217;m planning on being powered by Comb. The first is my <a href="http://examples.drewcking.com">Code Examples</a> site, which will serve two purposes: it&#8217;ll be a place to host demos of basic code for the blog entries I write, and it&#8217;ll be a testbed for integrating new features into the framework.  And yes, the code that runs the examples site is Comb itself.  The other projects will be revealed in time&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.drewcking.com/2008/05/comb-auto_prepend_file-output-buffering-and-mod_rewrite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
