<?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>Josh Highland &#187; php</title>
	<atom:link href="http://joshhighland.com/blog/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://joshhighland.com/blog</link>
	<description>the living internet</description>
	<lastBuildDate>Fri, 20 Jan 2012 18:48:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Non-abstract method Foo::bar() must contain body</title>
		<link>http://joshhighland.com/blog/2011/12/01/non-abstract-method-foobar-must-contain-body/</link>
		<comments>http://joshhighland.com/blog/2011/12/01/non-abstract-method-foobar-must-contain-body/#comments</comments>
		<pubDate>Fri, 02 Dec 2011 04:00:48 +0000</pubDate>
		<dc:creator>Josh Highland</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[error code]]></category>

		<guid isPermaLink="false">http://joshhighland.com/blog/?p=14731</guid>
		<description><![CDATA[I was working on one of my PHP based projects, and I was getting the following error: Non-abstract method Foo::bar() must contain body in Foo.php on line 10 The problem was that I had accidentally put a semicolon at the end of the first line of the function: WRONG WAY: class Foo &#123; function bar&#40;&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I was working on one of my PHP based projects, and I was getting the following error:</p>
<blockquote><p>Non-abstract method Foo::bar() must contain body in Foo.php on line 10</p></blockquote>
<p>The problem was that I had accidentally put a semicolon at the end of the first line of the function:</p>
<p>WRONG WAY:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Foo 
<span style="color: #009900;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">function</span> bar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// extra semicolon! </span>
    <span style="color: #009900;">&#123;</span> 
        <span style="color: #666666; font-style: italic;">// stuff </span>
    <span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>RIGHT WAY:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Foo 
<span style="color: #009900;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">function</span> bar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>    <span style="color: #666666; font-style: italic;">// no semicolon, yay </span>
    <span style="color: #009900;">&#123;</span> 
        <span style="color: #666666; font-style: italic;">// stuff </span>
    <span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://joshhighland.com/blog/2011/12/01/non-abstract-method-foobar-must-contain-body/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Letting the database to the heavy lifting: Capitalization via SQL</title>
		<link>http://joshhighland.com/blog/2011/02/12/letting-the-database-to-the-heavy-lifting-capitalization-via-sql/</link>
		<comments>http://joshhighland.com/blog/2011/02/12/letting-the-database-to-the-heavy-lifting-capitalization-via-sql/#comments</comments>
		<pubDate>Sun, 13 Feb 2011 07:33:04 +0000</pubDate>
		<dc:creator>Josh Highland</dc:creator>
				<category><![CDATA[coldfusion]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Capitalization]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[ucfirst]]></category>

		<guid isPermaLink="false">http://joshhighland.com/blog/?p=14626</guid>
		<description><![CDATA[Years ago I had the pleasure of meeting Ben Forta and listen to his thoughts on web development. One thing that stuck with me was his statement that: &#8220;Dynamic programming languages like PHP and Coldfusion are great, but developers need to leverage the database more. Allow the database to do it&#8217;s job, the heavy lifting&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><img class="alignleft size-full wp-image-14627" title="Letting the database to the heavy lifting: Capitalization via SQL " src="http://joshhighland.com.s3.amazonaws.com/blog/wp-content/uploads/2011/02/databaseStrength.jpg" alt="databaseStrength Letting the database to the heavy lifting: Capitalization via SQL " width="332" height="318" />Years ago I had the pleasure of meeting <a href="http://en.wikipedia.org/wiki/Ben_Forta">Ben Forta</a> and listen to his  thoughts on web development. One thing that stuck with me was his  statement that:</p>
<blockquote><p><em>&#8220;Dynamic programming languages like PHP and Coldfusion  are great, but developers need to leverage the database more. Allow the  database to do it&#8217;s job, the heavy lifting&#8221;</em></p></blockquote>
<p>With that being said, I was recently working with a database that  contained users first names. The data was not snantized at entry, and  contained a mix of lower cased (ex. josh) and upper cased (ex. Josh)  first characters in the firstname column. I needed to always present the  users first name in a capitalized format.</p>
<p>The first solution that most developers would reach for is  dynamically parsing the users first name, then upper-casing the first character. This works, but in my opinion isn&#8217;t the most elegant solution.</p>
<p>With a simple SQL statement, like the one below, we can return the users first name already in a capitalized state.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">UPPER</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">LEFT</span><span style="color: #66cc66;">&#40;</span>firstname<span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">+</span><span style="color: #993333; font-weight: bold;">SUBSTRING</span><span style="color: #66cc66;">&#40;</span>firstname<span style="color: #66cc66;">,</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span>LEN<span style="color: #66cc66;">&#40;</span>firstname<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> firstname 
<span style="color: #993333; font-weight: bold;">FROM</span> users</pre></div></div>

<div>It&#8217;s quick to implement, its easy to work with, and it&#8217;s also very fast on the performance scale.</div>
<div></div>
<div>Yes, I understand that there are cool convenience functions in like <a href="http://php.net/manual/en/function.ucfirst.php">ucfirst()</a> in PHP, but I&#8217;m a lazy programmer and I don&#8217;t want to have to remember  to use <a href="http://php.net/manual/en/function.ucfirst.php">ucfirst()</a> every time I&#8217;m dealing with the users name. I&#8217;d rather get  the information in the correct format the first time, then remembering  to groom it every time before I use it. Set it and forget it.</div>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://joshhighland.com/blog/2011/02/12/letting-the-database-to-the-heavy-lifting-capitalization-via-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP and cURL in parallel</title>
		<link>http://joshhighland.com/blog/2011/01/12/php-and-curl-in-parallel/</link>
		<comments>http://joshhighland.com/blog/2011/01/12/php-and-curl-in-parallel/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 06:26:45 +0000</pubDate>
		<dc:creator>Josh Highland</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://joshhighland.com/blog/?p=14607</guid>
		<description><![CDATA[I was recently working on a php based project for a client. I needed to pull in content from 10 different URLs, then process that data into something useful. I have a growing love affair with cURL, so it was my natural selection for the project. In my first approach, I looped over the list [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><img class="alignleft size-full wp-image-14570" title="PHP and cURL in parallel" src="http://joshhighland.com.s3.amazonaws.com/blog/wp-content/uploads/2010/11/curl.png" alt="curl PHP and cURL in parallel" width="200" height="200" />I was recently working on a php based project for a client. I needed to  pull in content from 10 different URLs, then process that data into  something useful.</p>
<p>I have a <a href="http://joshhighland.com/blog/tag/curl/">growing love affair with cURL</a>, so it was my natural selection for the project.</p>
<p>In my first approach, I looped over the list of URLs, sent the cURL  request, wait for the response, stored the data. repeat until done.</p>
<p>That worked, but it was very slow process. The page was taking between 30 &#8211;  45 seconds to load. That doesn&#8217;t sound long, but in terms of web applications,  that&#8217;s an eternity.</p>
<p>I tried several tricks to speed the application up, but the bottle  neck was the cURL calls. Each call was done in a synchronous manner.  Every call to cURL had to be completed before the next could be made.</p>
<p>After doing to research on how to speed this up, I came across the following php <a href="http://php.net/manual/en/book.curl.php">cURL functions</a>:</p>
<blockquote><p>curl_multi_init();<br />
curl_multi_add_handle();<br />
curl_multi_select();<br />
curl_multi_exec();<br />
curl_multi_getcontent();<br />
curl_multi_info_read();<br />
curl_multi_remove_handle();</p></blockquote>
<p>Using these methods allow for cURL to send asynchronous requests, solving my pervious problem.</p>
<p>A little more searching, and I found an awesome wrapper library that  takes the guesswork out of the using the curl_multi methods.  &#8220;ParallelCurl&#8221; <a href="https://github.com/petewarden/ParallelCurl" target="_blank">https://github.com/petewarden/ParallelCurl</a></p>
<p>The sample code provided with the library was very straight forward and super easy to use.</p>
<p>After  using asynchronous cURL calls via the <a href="https://github.com/petewarden/ParallelCurl">ParallelCurl library</a>, I was  able to reduce the page load time <strong>from 45 seconds to 15 seconds</strong>. It&#8217;s  still slow, but it&#8217;s a HUGE improvement, and it makes the application usable,  and reduces load on my server. It&#8217;s a win-win-win situation!</p>
]]></content:encoded>
			<wfw:commentRss>http://joshhighland.com/blog/2011/01/12/php-and-curl-in-parallel/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using cURL and PHP to upload files through a form post</title>
		<link>http://joshhighland.com/blog/2010/11/27/using-curl-and-php-to-upload-files-through-a-form-post/</link>
		<comments>http://joshhighland.com/blog/2010/11/27/using-curl-and-php-to-upload-files-through-a-form-post/#comments</comments>
		<pubDate>Sat, 27 Nov 2010 23:22:49 +0000</pubDate>
		<dc:creator>Josh Highland</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[file upload]]></category>

		<guid isPermaLink="false">http://joshhighland.com/blog/?p=14559</guid>
		<description><![CDATA[Lately I have been working on a project that requires me to use PHP to interact with a REST based service. cURL is the logical choice for making HTTP calls to the REST service. I love cURL, I&#8217;ve blogged about it before, but I recently ran into some major issues. The REST service I was [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><img class="alignleft size-full wp-image-14570" title="Using cURL and PHP to upload files through a form post" src="http://joshhighland.com.s3.amazonaws.com/blog/wp-content/uploads/2010/11/curl.png" alt="curl Using cURL and PHP to upload files through a form post" width="200" height="200" /></p>
<p>Lately I have been working on a project that requires me to use PHP to  interact with a REST based service. cURL is the logical choice for  making HTTP calls to the REST service.</p>
<p>I love cURL, <a href="http://joshhighland.com/blog/2009/01/27/let-curl-do-your-heavy-lifting/">I&#8217;ve blogged about it before</a>, but I recently ran into some major issues.</p>
<p>The  REST service I was using required me to send two files along with some  meta information. easy enough. I used the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$postFields</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><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;">//files</span>
<span style="color: #000088;">$postFields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;@<span style="color: #006699; font-weight: bold;">$filePath</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$postFields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'thumbnail'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;@<span style="color: #006699; font-weight: bold;">$thumbnailPath</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//metaData</span>
<span style="color: #000088;">$postFields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$title</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$postFields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'description'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$description</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$postFields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tags'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$tags</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$postFields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'licenseinfo'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$licenseinfo</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$postFields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'token'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$userToken</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$curl_handle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl_handle</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$api_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl_handle</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl_handle</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl_handle</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #000088;">$http_post_fields</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//execute the API Call</span>
<span style="color: #000088;">$returned_data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl_handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The  code worked great, sending an &#8220;at&#8221; sign (@) before the file path  makes sure that cURL sends the file as part of a &#8220;multipart/form-data&#8221;  post. Exactly what we needed.</p>
<p>The form post from cURL worked great, but the REST service was  retuning a 400 error and saying &#8220;The specified thumbnail file is not  supported.&#8221;. I was at a loss. The service documentation stated the &#8220;jpg,  jpeg, gif, and png&#8221; files were supported.</p>
<p>I ended up contacting the developers of the service who told me that  the content type for the file had to be set to &#8220;image/jpg&#8221; (for jpg).</p>
<p>After pouring through the cURL documentation and not finding anything about  how to set the content type for a single file in a &#8220;multipart/form-data&#8221;  post, I turned to Goolge. My searches with about as helpful as the cURL  docs. I sent a few hours hacking my code and trying some things, I ever  read some posts from 2008 saying that is was not possible to do. Then, I  got a break through, a single ray of light. On a message board was a  single sentence replay. &#8220;You should try this&#8230; $image;type=image/jpg&#8221;.</p>
<p>That was the break through I needed. Below is final updated code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$postFields</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><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;">//files</span>
 <span style="color: #000088;">$postFields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;@<span style="color: #006699; font-weight: bold;">$filePath</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//get the extension of the image file</span>
<span style="color: #000088;">$tumbnailExtention</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^.*\.([^.]+)$/D'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'$1'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$thumbnailPath</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$postFields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'thumbnail'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;@<span style="color: #006699; font-weight: bold;">$thumbnailPath</span>;type=image/<span style="color: #006699; font-weight: bold;">$tumbnailExtention</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//metaData</span>
<span style="color: #000088;">$postFields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$title</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$postFields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'description'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$description</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$postFields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tags'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$tags</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$postFields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'licenseinfo'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$licenseinfo</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$postFields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'token'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$userToken</span>&quot;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #000088;">$curl_handle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl_handle</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$api_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl_handle</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl_handle</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl_handle</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #000088;">$http_post_fields</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">//execute the API Call</span>
<span style="color: #000088;">$returned_data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl_handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In summary, if you need to set the content type of a file being sent an image through cURL, via a POST, use the following format:<br />
<strong>$postFields['file'] = &#8220;@PATHTOFILE;type=CONTENTTYPEHERE&#8221;;</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://joshhighland.com/blog/2010/11/27/using-curl-and-php-to-upload-files-through-a-form-post/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Removing trailing comas with PHP</title>
		<link>http://joshhighland.com/blog/2009/11/02/removing-trailing-comas-with-php/</link>
		<comments>http://joshhighland.com/blog/2009/11/02/removing-trailing-comas-with-php/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 22:30:56 +0000</pubDate>
		<dc:creator>Josh Highland</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[regular expression]]></category>

		<guid isPermaLink="false">http://joshhighland.com/blog/?p=940</guid>
		<description><![CDATA[Dealing with trailing comas in lists is common problem for developers. I found the best way to handle this situation in PHP is with the following regular expression. $string = eregi_replace&#40;',$', '', $string&#41;; Before: string = &#8220;2, 6, 9,&#8221; After: string = &#8220;2, 6, 9&#8243; Only the trailing coma will be stripped. If no coma [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><img class="alignleft size-full wp-image-939" title="Removing trailing comas with PHP" src="http://joshhighland.com.s3.amazonaws.com/blog/wp-content/uploads/2009/11/php_logo_medium.jpg" alt="php logo medium Removing trailing comas with PHP" width="200" height="108" />Dealing with trailing comas in lists is common problem for developers. I found the best way to handle this situation in PHP is with the following regular expression.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">eregi_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">',$'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Before:</strong> string = &#8220;2, 6, 9,&#8221;<strong><br />
After:</strong> string = &#8220;2, 6, 9&#8243;</p>
<p>Only the trailing coma will be stripped. If no coma is found, the string simply passes through. It&#8217;s a simple and effective solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://joshhighland.com/blog/2009/11/02/removing-trailing-comas-with-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Create WordPress Thumbnails Automatically</title>
		<link>http://joshhighland.com/blog/2009/09/29/create-wordpress-thumbnails-automatically/</link>
		<comments>http://joshhighland.com/blog/2009/09/29/create-wordpress-thumbnails-automatically/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 00:19:29 +0000</pubDate>
		<dc:creator>Josh Highland</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[automatically]]></category>
		<category><![CDATA[custom fields]]></category>
		<category><![CDATA[premium theme]]></category>
		<category><![CDATA[thumbnail]]></category>
		<category><![CDATA[timthumb]]></category>

		<guid isPermaLink="false">http://joshhighland.com/blog/?p=887</guid>
		<description><![CDATA[WordPress has the ability to allow post authors to assign custom fields to a post. This arbitrary extra information is known as meta-data. This meta-data can be used by theme authors to do some pretty cool things. The theme I am currently using allows for a custom field named &#8220;thumb&#8221;. If you create the &#8220;thumb&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><img class="alignleft size-medium wp-image-890" title="Create Wordpress Thumbnails Automatically" src="http://joshhighland.com.s3.amazonaws.com/blog/wp-content/uploads/2009/09/create-wordpress-thumbnails-300x300.jpg" alt="create wordpress thumbnails 300x300 Create Wordpress Thumbnails Automatically" width="300" height="300" />WordPress has the ability to allow post authors to assign custom fields to a post. This arbitrary extra information is known as meta-data. This meta-data can be used by theme authors to do some pretty cool things.</p>
<p>The <a href="http://www.studiopress.com/themes/church">theme</a> I am currently using allows for a custom field named &#8220;thumb&#8221;. If you create the &#8220;thumb&#8221; custom field in a post and pass in the path to an image, for example &#8220;wp-content/uploads/2008/12/wordpress_logo.png&#8221;, a thumb nail version of the image will appear next the posts title on the home page of my blog. Awesome stuff.</p>
<p>When I discovered this theme and the &#8220;thumb&#8221; custom field, I already had 225 posts in my blog. I didn&#8217;t want to go back and manually create all the custom fields for the existing posts, so I wrote a PHP script to do it for me.</p>
<p>The PHP script cycles through your existing posts and looks for the first image in the post, and creates the thumb field based on it&#8217;s location. The script is configurable, your theme may want a different custom field name, like &#8220;thumbnail&#8221; or &#8220;image&#8221;.</p>
<p>This code is provided as is. If you aren&#8217;t a developer, you should be messing with stuff like this. Be sure to <a href="http://wordpress.org/extend/plugins/wp-db-backup/">back up your wordpress database</a> before running this.</p>
<p><strong>Instruction:<br />
</strong></p>
<ul>
<li>download this code</li>
<li>configure the database connection info and custom field name</li>
<li>upload this code onto your server</li>
<li>point your browser to the file</li>
<li>watch the script do it&#8217;s magic</li>
<li>remove the file from your server</li>
<li><a href="https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&amp;content_ID=marketing_us/send_money" target="_blank">donate $2 to my paypal account</a> (joshhighland@gmail.com)</li>
</ul>
<p><strong>Note:</strong> This is a one time deal, when you create new posts you will need to add the &#8220;thumb&#8221; field and image path manually</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//your database configuration information</span>
<span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;YOUR_USER_NAME&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;YOUR_PASSWORD&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$database</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;DATABASE&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$databaseLocation</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//name of the Custom Field to use</span>
<span style="color: #000088;">$customFieldName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;thumb&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/******************* END CONFIGURATION *****************************/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//get the wordpress posts to work with</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM wp_posts&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$mysqli</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$query</span>&quot;</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;">//loop over all the posts</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch_object</span><span style="color: #009900;">&#40;</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;">//get all the info from the post that we need to work with</span>
		<span style="color: #000088;">$cur_post_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$cur_post_content</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_content</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//the pattern to find the html image tag</span>
		<span style="color: #000088;">$pattern</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/]+src[\\s=\'&quot;]'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$pattern</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'+([^&quot;\'&gt;\\s]+)/is'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//try to match the pattern against the post content</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pattern</span><span style="color: #339933;">,</span><span style="color: #000088;">$cur_post_content</span><span style="color: #339933;">,</span><span style="color: #000088;">$match</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;">//break up the image path</span>
			<span style="color: #000088;">$pieces</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;wp-content/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$match</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">//make sure the file name isnt empty</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pieces</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #666666; font-style: italic;">//build the file path</span>
				<span style="color: #000088;">$imagePath</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;wp-content/&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$pieces[1]</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">//insert the custom field for the post</span>
				<span style="color: #000088;">$insertQuery</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO wp_postmeta (post_id, meta_key, meta_value) VALUES (<span style="color: #006699; font-weight: bold;">$cur_post_id</span>, '<span style="color: #006699; font-weight: bold;">$customFieldName</span>', '<span style="color: #006699; font-weight: bold;">$imagePath</span>')&quot;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #000088;">$mysqli</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$insertQuery</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">//debugging stuff</span>
&nbsp;
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$mysqli</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errno</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;failed: <span style="color: #009933; font-weight: bold;">%s</span> <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mysqli</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #b1b100;">else</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;..... inserting <span style="color: #006699; font-weight: bold;">$imagePath</span> <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #990000;">flush</span><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>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;---completed---&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://joshhighland.com/blog/2009/09/29/create-wordpress-thumbnails-automatically/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How I do layouts and views in CodeIgniter</title>
		<link>http://joshhighland.com/blog/2008/11/09/how-i-do-layouts-and-views-in-codeigniter/</link>
		<comments>http://joshhighland.com/blog/2008/11/09/how-i-do-layouts-and-views-in-codeigniter/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 03:07:53 +0000</pubDate>
		<dc:creator>Josh Highland</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://joshhighland.com/blog/?p=445</guid>
		<description><![CDATA[I have been a loyal fan of the kick-ass php framework, codeIgniter, for some time now. A while back I made a post on how to improve the view handling of codeIgniter. I would like to retract that post. Through the comments on that post I found out about an undocumented parameter (as of version [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><img class="size-full wp-image-443 alignleft" title="How I do layouts and views in CodeIgniter" src="http://joshhighland.com.s3.amazonaws.com/blog/wp-content/uploads/2008/11/codeigniter_logo.jpg" alt="codeigniter logo How I do layouts and views in CodeIgniter" width="91" height="101" />I have been a loyal fan of the kick-ass php framework, codeIgniter, for some time now. A while back I made a post on <a href="http://joshhighland.com/blog/2008/04/29/improving-codeigniters-view-handling/">how to improve the view handling of codeIgniter</a>. I would like to retract that post. Through the comments on that post I found out about an undocumented parameter (as of version 1.7, it has been <a href="http://codeigniter.com/user_guide/general/views.html">documented</a>) that allows view to be rendered into a variable. This changes everything, and totally negates any of the complaint I had about how CI handles layouts and views.</p>
<p>Below is an example of live code I have running at <a href="http://loudsongs.com">loudsongs.com</a>. It shows how I have been able to take advantage of of this powerful third parameter that stops CI from rendering a view to the screen when loading it.</p>
<p><strong><br />
</strong><strong>Inside of my controller</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
 <span style="color: #000088;">$base_url</span> <span style="color: #339933;">=</span> base_url<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;">//what the nav needs</span>
 <span style="color: #000088;">$navigation_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'navTab'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;home&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//basic info for the header</span>
 <span style="color: #000088;">$layout_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pageTitle'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;LoudSon.gs&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$layout_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'meta_description'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Under Ground Lyrics, hardcore, metal, emo, rock&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$layout_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'meta_keywords'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;lyrics,song,songs,words,hardore,metal,emo,rock&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$layout_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'meta_url'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$base_url</span>&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$layout_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'meta_classification'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;home&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$layout_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'searchInput'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$layout_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'searchOptions'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'search'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$lastest_albums</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">search</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">last_n_albumsAdded</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$popular_songs</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">search</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">popular_n_songs</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//get the featured Albums</span>
 <span style="color: #000088;">$featuredAlbums</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">search</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFeaturedAlbums</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$body_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'featured'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$featuredAlbums</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$body_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'newest'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$lastest_albums</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$body_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'popular'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$popular_songs</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//load the content variables</span>
 <span style="color: #000088;">$layout_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'content_navigation'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'navigation'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$navigation_data</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$layout_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'content_body'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'home/homePage'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body_data</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</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;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'layouts/main'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$layout_data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>/views/navigation.php</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;div id=&quot;header&quot;&gt;
 &lt;h1 title=&quot;Loud Songs Logo&quot;&gt;LoudSongs search - hard to find obscure lyrics&lt;/h1&gt;
&nbsp;
&lt;ul title=&quot;navigation&quot;&gt;
 &lt;li <span style="color: #000000; font-weight: bold;">&lt;?</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$navTab</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;about&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; id=<span style="color: #000099; font-weight: bold;">\&quot;</span>active<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span> base_url<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>about&quot; title=&quot;About Page&quot;&gt;About&lt;/a&gt;&lt;/li&gt;
 &lt;li <span style="color: #000000; font-weight: bold;">&lt;?</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$navTab</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;add&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; id=<span style="color: #000099; font-weight: bold;">\&quot;</span>active<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span> base_url<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>add&quot; title=&quot;Add Lyrics&quot;&gt;Add Lyrics&lt;/a&gt;&lt;/li&gt;
 &lt;li <span style="color: #000000; font-weight: bold;">&lt;?</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$navTab</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;home&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; id=<span style="color: #000099; font-weight: bold;">\&quot;</span>active<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span> base_url<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; title=&quot;Home Page&quot;&gt;Home&lt;/a&gt;&lt;/li&gt;
 &lt;/ul&gt;
 &lt;/div&gt;</pre></div></div>

<p><strong>/views/home/homePage.php</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;div&gt;
 Thanks for visiting LoudSongs
 &lt;br/&gt;
 We are trying to build a maintain a collection of punk rock, hardcore, emo, metal and other lyrics.
 This website is free and open to all.
 Please help us by &lt;a href=&quot;http://www.LoudSon.gs/add&quot;&gt;contributing to the collection&lt;/a&gt;.
 &lt;/div&gt;
&nbsp;
&lt;div&gt;
 <span style="color: #000000; font-weight: bold;">&lt;?</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'home/featuredAlbums'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
 &lt;/div&gt;
&nbsp;
&lt;div class=&quot;middle_col_split&quot;&gt;
 <span style="color: #000000; font-weight: bold;">&lt;?</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'home/recentlyAdded'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
 &lt;/div&gt;
&nbsp;
&lt;div class=&quot;middle_col_split&quot;&gt;
 <span style="color: #000000; font-weight: bold;">&lt;?</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'home/mostPopularSongs'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
 &lt;/div&gt;</pre></div></div>

<p><strong>/views/layouts/main.php</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
 &lt;html&gt;
 &lt;head&gt;
 &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html;charset=us-ascii&quot;&gt;
 &lt;meta name=&quot;description&quot; content=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$meta_description</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
 &lt;meta name=&quot;keywords&quot; content=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$meta_keywords</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
 &lt;meta http-equiv=&quot;expires&quot; content=&quot;0&quot; /&gt;
 &lt;meta name=&quot;classification&quot; content=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$meta_classification</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
 &lt;meta name=&quot;Robots&quot; content=&quot;index,follow&quot;&gt;
 &lt;meta name=&quot;revisit-after&quot; content=&quot;2 Days&quot;&gt;
 &lt;meta name=&quot;language&quot; content=&quot;en-us&quot;&gt;
&nbsp;
&lt;link href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span> base_url<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>includes/styles/lyrics.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;screen&quot; title=&quot;default&quot;&gt;
&nbsp;
&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot; src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span> base_url<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>includes/scripts/jquery-1.2.6.min.js&quot;&gt;&lt;/script&gt;
&nbsp;
&lt;title&gt;<span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$pageTitle</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/title&gt;
 &lt;/head&gt;
&nbsp;
&lt;body id=&quot;home&quot;&gt;
 &lt;div id=&quot;nav&quot;&gt;
 <span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$content_navigation</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
 &lt;/div&gt;
&nbsp;
&lt;div id=&quot;middle_column&quot;&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$content_body</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;/div&gt;
 &lt;/body&gt;
&nbsp;
&lt;/html&gt;</pre></div></div>

<p><strong><br />
</strong></p>
<p>wow, ok, so that might be a lot to digest. The bottom line is this, CI doesnt have &#8220;layouts&#8221; like other frameworks, so you have to become creative and use a view AS a layout by using the mythical 3rd parameter when loading a view. We load data into the navigation view and store all of that into the $layout_data array, then we load a view named homePage and pass data into it, and stor it into the $layout_data array. When we are done loading all of the views into the array, we pass that array into another view. This view acts as our layout. easy as that! check it out below:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//load the content variables</span>
 <span style="color: #000088;">$layout_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'content_navigation'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'navigation'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$navigation_data</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$layout_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'content_body'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'home/homePage'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body_data</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</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;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'layouts/main'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$layout_data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I hope this helps someone understand how codeigniter does have layout and view functionality, you just have to structure it that way in your code.</p>
<p>post some comments if you need more clarification.</p>
]]></content:encoded>
			<wfw:commentRss>http://joshhighland.com/blog/2008/11/09/how-i-do-layouts-and-views-in-codeigniter/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Improving CodeIgniters View Handling</title>
		<link>http://joshhighland.com/blog/2008/04/29/improving-codeigniters-view-handling/</link>
		<comments>http://joshhighland.com/blog/2008/04/29/improving-codeigniters-view-handling/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 00:43:11 +0000</pubDate>
		<dc:creator>Josh Highland</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://joshhighland.com/blog/?p=279</guid>
		<description><![CDATA[Please be aware that I no longer use this method. Please follow this link to see how I handle layout with Codeigniter If you have ever worked with an MVC framework for web developent, you know that the &#8220;V&#8221; stands for &#8220;view&#8221;. At work, I program in coldfusion, and use the coldbox framework, and I [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><img class="alignnone size-full wp-image-278" title="Improving CodeIgniters View Handling" src="http://joshhighland.com.s3.amazonaws.com/blog/wp-content/uploads/2008/04/codeigniter_logo.jpg" alt="codeigniter logo Improving CodeIgniters View Handling" width="91" height="101" /></p>
<blockquote><p><strong>Please be aware that I no longer use this method. Please follow<a href="http://joshhighland.com/blog/2008/11/09/how-i-do-layouts-and-views-in-codeigniter/"> this link to see how I handle layout with Codeigniter</a></strong></p></blockquote>
<p>If you have ever worked with an MVC framework for web developent, you know that the &#8220;V&#8221; stands for &#8220;view&#8221;.</p>
<p>At work, I program in coldfusion, and use the <a href="http://coldboxframework.com/">coldbox framework</a>, and I love it. At home, I write PHP code, with the <a href="http://codeigniter.com">codeigniter framework</a>.</p>
<p>I love codeigniter, but I think that its biggest weakness is the <a href="http://codeigniter.com/user_guide/general/views.html">view handeling</a>, all thought codeigniter had taken strides to improve it. At the time of writing this, codeigniter is at version 1.6.1, and allows multiple views to be loaded at one time.</p>
<p>example:</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>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Page <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
 <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page_title'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Your title'</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'header'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'menu'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'content'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'footer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
 <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This is great with one exception, codeigniter simple builds a stack of the view results, appending them to each other.</p>
<p>This means that in header.php, loaded at the start of the view sequence, we would have to opening tags, such as &lt;body&gt;, and then in the last view, footer, we have to close the tags we opened in header.php, in this case, &lt;/body&gt;</p>
<p>I don&#8217;t know about you, but opening tags in open file, and depending on another file to close them is not a good practice. Using a MVC setup and then doing something like this is very counter intuitive.</p>
<p>To fix this, codeigniter needs to support layouts, as well as views.</p>
<p>A layout is a file that contains the framework for a page, and the views are included and rendered inside the layout. basically filling out the content of the page. This also leaves your code the ability to be more flexible. Your views are pluggable components that don&#8217;t care about the layout at all.</p>
<p>One of the reasons I love open source software is the fact that the community will fix weaknesses is the software. Looking at the <a href="http://www.codeigniter.com/wiki">codeigniter wiki</a>, I came across the <a href="http://codeigniter.com/wiki/View_Object/">&#8220;view object&#8221; (http://codeigniter.com/wiki/View_Object/)</a></p>
<p>The view object is a great solution for adding layouts to the codeigniter framework.<br />
Here is a code sample of how to use the view object in a controller:</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;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'view'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>         <span style="color: #666666; font-style: italic;">// or autoload</span>
&nbsp;
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">layout</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'admin/layout'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>              <span style="color: #666666; font-style: italic;">// set the view data</span>
 <span style="color: #0000ff;">'privileges'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$privileges</span><span style="color: #339933;">,</span>
 <span style="color: #0000ff;">'catcode'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
 <span style="color: #0000ff;">'page'</span>       <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$page</span><span style="color: #339933;">,</span>
 <span style="color: #009900;">&#41;</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;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>             <span style="color: #666666; font-style: italic;">// load the page partials</span>
 <span style="color: #0000ff;">'header'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'header'</span><span style="color: #339933;">,</span>
 <span style="color: #0000ff;">'menu'</span>       <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'menu'</span><span style="color: #339933;">,</span>
 <span style="color: #0000ff;">'content'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'admin/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$page</span><span style="color: #339933;">,</span>
 <span style="color: #0000ff;">'footer'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'footer'</span><span style="color: #339933;">,</span>
 <span style="color: #009900;">&#41;</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;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>               <span style="color: #666666; font-style: italic;">// create the view or</span></pre></div></div>

<p>inside the layout file (admin/layout.php)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span> <span style="color: #000088;">$header</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;body&gt;
 <span style="color: #000000; font-weight: bold;">&lt;?</span> <span style="color: #000088;">$menu</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
 &lt;div id=&quot;mainContent&quot;&gt;
 <span style="color: #000000; font-weight: bold;">&lt;?</span> <span style="color: #000088;">$content</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
 &lt;/div&gt;
 &lt;/body&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?</span> <span style="color: #000088;">$footer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>You can see that the layout file contains the framework of the page, freeing up the views to be individual pluggable items that can be used across your codeigniter application.</p>
<p>I hope that the codeigniter team takes note of the view object and adds it to the core for codeignier 1.7 or maybe even sooner!</p>
]]></content:encoded>
			<wfw:commentRss>http://joshhighland.com/blog/2008/04/29/improving-codeigniters-view-handling/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic (Feed is rejected)
Page Caching using disk: enhanced
Database Caching 9/59 queries in 0.032 seconds using disk: basic
Object Caching 897/1008 objects using disk: basic
Content Delivery Network via Amazon Web Services: S3: joshhighland.com.s3.amazonaws.com

Served from: joshhighland.com @ 2012-02-06 22:16:35 -->
