<?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>robotslacker</title>
	<atom:link href="http://robotslacker.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://robotslacker.com</link>
	<description>Just Another Wordpress Blaaahg</description>
	<lastBuildDate>Mon, 16 Jan 2012 23:21:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Rails 3 Routes Configuration &#8211; Dynamic Segments, Constraints and Scope</title>
		<link>http://robotslacker.com/2012/01/rails-3-routes-configuration-dynamic-segments-constraints-and-scope/</link>
		<comments>http://robotslacker.com/2012/01/rails-3-routes-configuration-dynamic-segments-constraints-and-scope/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 08:25:30 +0000</pubDate>
		<dc:creator>calvin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://robotslacker.com/?p=75</guid>
		<description><![CDATA[I&#8217;ve been messing around with Rails for the past few months, and I just got through figuring this out so I thought I&#8217;d post this here. Sometimes you want to have a dynamic segment in a route. For example: /:username, to allow your users to have vanity urls. You might use something like this: &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been messing around with Rails for the past few months, and I just got through figuring this out so I thought I&#8217;d post this here. </p>
<p>Sometimes you want to have a dynamic segment in a route. For example: <code class="codecolorer text twitlight"><span class="text">/:username</span></code>, to allow your users to have vanity urls. You might use something like this:</p>
<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; get <span style="color:#996600;">'/:username'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'profiles#show'</span></div></div>
<p>However, you obviously don&#8217;t want routes like /login or /logout to be routed to your controller (in the above case, the profiles controller). In this case we would use <b>segment constraints</b>. Rails allows you to use either a regular expression as shown in <a href="http://guides.rubyonrails.org/routing.html#segment-constraints">this rails guide on segment constraints</a>.</p>
<p>The other method is to use a Constraint class:</p>
<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; get <span style="color:#996600;">'/:username'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'profiles#show'</span>, <span style="color:#ff3333; font-weight:bold;">:constraints</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ProfileConstraint</div></div>
<p>Reference the ProfileConstraint class by creating a new directory/file called <code class="codecolorer text twitlight"><span class="text">app/constraints/profile_constraint.rb</span></code>:</p>
<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> ProfileConstraint<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">matches</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>request<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; reserved_words = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'login'</span>, <span style="color:#996600;">'signup'</span>, <span style="color:#996600;">'signout'</span>, <span style="color:#996600;">'welcome'</span>, <span style="color:#996600;">'home'</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; !reserved_words.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>request.<span style="color:#9900CC;">path_parameters</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:username</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>Above, Rails looks for the <code class="codecolorer text twitlight"><span class="text">matches?</span></code> method in <code class="codecolorer text twitlight"><span class="text">ProfileConstraint</span></code> sends it a <code class="codecolorer text twitlight"><span class="text">request</span></code> object, which we then use to decide whether to match the route or not by comparing it against an array of reserved_words. </p>
<p>Another useful way to add on to the above would be to use <code class="codecolorer text twitlight"><span class="text">scope</span></code>. This allows you to extend your route like <code class="codecolorer text twitlight"><span class="text">/:username/comments</span></code>:</p>
<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">scope <span style="color:#996600;">'/:username'</span>, <span style="color:#ff3333; font-weight:bold;">:constraints</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ProfileConstraint <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; get <span style="color:#996600;">''</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'profiles#show'</span><br />
&nbsp; get <span style="color:#996600;">'/comments'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'profile#comments'</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>And now you&#8217;ll have routes like so:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GET &nbsp; &nbsp; &nbsp; &nbsp;/:username(.:format) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {:controller=&gt;&quot;profiles&quot;, :action=&gt;&quot;show&quot;}<br />
following GET &nbsp; &nbsp; &nbsp; &nbsp;/:username/comments(.:format) &nbsp; &nbsp; &nbsp; &nbsp; {:controller=&gt;&quot;profiles&quot;, :action=&gt;&quot;comments&quot;}</div></div>
<p>Hope someone finds this useful as I did.</p>
<p>Tips for improving:<br />
- Dynamically add model/controller classnames and routes to the <code class="codecolorer text twitlight"><span class="text">reserved_words</span></code> array.</p>
]]></content:encoded>
			<wfw:commentRss>http://robotslacker.com/2012/01/rails-3-routes-configuration-dynamic-segments-constraints-and-scope/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Extending CodeIgniter&#8217;s Active Record Class</title>
		<link>http://robotslacker.com/2011/05/extending-codeigniters-active-record-class/</link>
		<comments>http://robotslacker.com/2011/05/extending-codeigniters-active-record-class/#comments</comments>
		<pubDate>Wed, 04 May 2011 21:04:03 +0000</pubDate>
		<dc:creator>calvin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://robotslacker.com/?p=51</guid>
		<description><![CDATA[If you&#8217;re here you&#8217;ve probably realized by now that CodeIgniter 2.0 doesn&#8217;t officially support extending the core Active Record class, which is a bit of a drag. As you may know, CI 2.0 came with a new core/ folder that allows you to simply drop classes to extend the CI core with. For example, to [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re here you&#8217;ve probably realized by now that CodeIgniter 2.0 doesn&#8217;t officially support extending the core Active Record class, which is a bit of a drag. </p>
<p>As you may know, CI 2.0 came with a new core/ folder that allows you to simply drop classes to extend the CI core with. </p>
<p>For example, to extend the base CI_Loader class, you would just drop in MY_Loader.php into the /application/core folder, and all is set and done. Of course, you&#8217;d make sure that the &#8216;subclass_prefix&#8217; config variable is set to &#8216;MY_&#8217;. This is the default configuration.</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'subclass_prefix'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'MY_'</span><span style="color: #339933;">;</span></div></div>
<p>Being able to just drop in subclasses in the core/ folder is pure awesome, because you don&#8217;t need to modify the core CI classes to extend its functionality, and you keep everything separate in each /application instance. </p>
<p>You may think you can just drop in a file called &#8220;MY_DB_active_rec.php&#8221; into the /application/core folder, but this is not the case. It will not work, as verified by Phil Sturgeon himself <a href="http://stackoverflow.com/questions/5083981/extending-the-ci-db-active-record-class-in-codeigniter-2-0">in this StackOverflow post</a>.</p>
<p>To do so requires a teeny bit of hacking of the core CI files. If you don&#8217;t like the idea of doing so, you may want to just head home now. </p>
<p>Still with me? The good news is that this only requires a few lines of code change. Here we go:</p>
<p>Locate the piece of code in</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">/system/database/DB.php</div></div>
<p>, starting on line 110 (as of CI 2.0.0):</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>BASEPATH<span style="color: #339933;">.</span><span style="color: #0000ff;">'database/DB_driver'</span><span style="color: #339933;">.</span>EXT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$active_record</span><span style="color: #009900;">&#41;</span> OR <span style="color: #000088;">$active_record</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>BASEPATH<span style="color: #339933;">.</span><span style="color: #0000ff;">'database/DB_active_rec'</span><span style="color: #339933;">.</span>EXT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">class_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'CI_DB'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'class CI_DB extends CI_DB_active_record { }'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>This is the bit of code that loads CI&#8217;s active record class. Replace it with this:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>BASEPATH<span style="color: #339933;">.</span><span style="color: #0000ff;">'database/DB_driver'</span><span style="color: #339933;">.</span>EXT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$active_record</span><span style="color: #009900;">&#41;</span> OR <span style="color: #000088;">$active_record</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>BASEPATH<span style="color: #339933;">.</span><span style="color: #0000ff;">'database/DB_active_rec'</span><span style="color: #339933;">.</span>EXT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// get the CI instance</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$CI</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span> get_instance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$prefix</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'subclass_prefix'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span>APPPATH<span style="color: #339933;">.</span><span style="color: #0000ff;">'core/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$prefix</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'DB_active_rec'</span><span style="color: #339933;">.</span>EXT<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>APPPATH<span style="color: #339933;">.</span><span style="color: #0000ff;">'core/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$prefix</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'DB_active_rec'</span><span style="color: #339933;">.</span>EXT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">class_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'CI_DB'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'class CI_DB extends '</span><span style="color: #339933;">.</span><span style="color: #000088;">$prefix</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'DB_active_record { }'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">class_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'CI_DB'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'class CI_DB extends CI_DB_active_record { }'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <br />
<span style="color: #009900;">&#125;</span></div></div>
<p>What happens here is that it will check the /application/core/ folder to see if a &#8220;MY_DB_active_rec.php&#8221; file exists (where MY_ is the prefix name you specified in your config file), and if it does, it loads that instead of the CI_DB_active_record class. </p>
<p>Next you&#8217;ll also need to extend the CI_Loader class to override the database() method, as well as the specific database driver that you&#8217;ll be using. In my case I extended the CI_DB_mysql_driver to override the _insert() method to allow the &#8220;INSERT DELAYED&#8221; feature of MySQL. </p>
<p>I&#8217;ve included a zip file of the changes. The files below were meant for CodeIgniter 2.0.0. CI 2.0.1+ shouldn&#8217;t be much more different, just get into the file and look around to make the necessary adjustments.</p>
<p><a href='http://robotslacker.com/wp-content/uploads/2011/05/extend_ci_active_record.zip'>Download extend_ci_active_record.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://robotslacker.com/2011/05/extending-codeigniters-active-record-class/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Dynamically combine and minify your Javascript and CSS files with CodeIgniter</title>
		<link>http://robotslacker.com/2010/11/dynamically-combine-and-minify-your-javascript-and-css-files-with-codeigniter/</link>
		<comments>http://robotslacker.com/2010/11/dynamically-combine-and-minify-your-javascript-and-css-files-with-codeigniter/#comments</comments>
		<pubDate>Sun, 21 Nov 2010 21:23:33 +0000</pubDate>
		<dc:creator>calvin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://robotslacker.com/?p=25</guid>
		<description><![CDATA[Update 10/27/2011: This method is outdated. I recommend using the very awesome Carabiner for your minification/concatenation needs. If you still want to stick to this method, I would recommend implementing some sort of caching for your minified/concatenated files. Carabiner does this for your automatically, however! &#8212;&#8212;&#8211; As any good UI developer will tell you, one [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update 10/27/2011:</strong> This method is outdated. I recommend using the very awesome <a href="http://codeigniter.com/wiki/Carabiner/">Carabiner</a> for your minification/concatenation needs. </p>
<p>If you still want to stick to this method, I would recommend implementing some sort of caching for your minified/concatenated files. Carabiner does this for your automatically, however!</p>
<p>&#8212;&#8212;&#8211;<br />
As any good UI developer will tell you, one of the <a href="http://developer.yahoo.com/performance/rules.html">best practices for speeding up your website</a> is to <b>minimize HTTP requests</b>. Since most of the user&#8217;s loading time is tied up in things like loading scripts, images, flash, stylesheets, etc., reducing the number of these requests can drastically help improve loading time. It also helps to Gzip the components as well, which we&#8217;ll also cover in this tutorial. </p>
<p>This first tutorial will cover how to concatenate and <a href="http://en.wikipedia.org/wiki/Minification_%28programming%29">minify</a> your javascript and CSS files into a single HTTP request, using the <a href="http://codeigniter.com">CodeIgniter framework</a>. For sites that load lots of scripts like jQuery plugins, this can be very beneficial for performance. Additionally, minification of scripts and stylesheets can help reduce the size of files, saving you bandwidth and shortening loading times for user. </p>
<p>So, let&#8217;s get started!</p>
<p><b>NOTE:</b> I am assuming in this tutorial that you are already using an .htaccess file to eliminate <code class="codecolorer text twitlight"><span class="text">index.php</span></code> from your URIs. </p>
<h2>Create an assets directory</h2>
<p>You&#8217;ll want to manage your static assets (js, css, images, etc) by placing them in a directory called /assets in your web root. Here&#8217;s what your CI folder structure should look like:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">/assets<br />
&nbsp; /css<br />
&nbsp; /images<br />
&nbsp; /js<br />
/system<br />
&nbsp; /application<br />
&nbsp; ...<br />
index.php</div></div>
<p>You may have your <code class="codecolorer text twitlight"><span class="text">application/</span></code> folder elsewhere, but for this tutorial we&#8217;ll have it in the default location, inside the <code class="codecolorer text twitlight"><span class="text">/system</span></code> folder.</p>
<p>You&#8217;ll also need the below two libraries, which are essential to this tutorial:</p>
<p>Let&#8217;s grab copies of the following two libraries:</p>
<p><a href="https://github.com/rgrove/jsmin-php/">JSMin-PHP</a>, Ryan Grove&#8217;s PHP port of Douglas Crockford&#8217;s JSMin.<br />
<a href="http://code.google.com/p/cssmin/">Joe Scylla&#8217;s CssMin</a></p>
<p>Name these two files <code class="codecolorer text twitlight"><span class="text">JSMin.php</span></code> and <code class="codecolorer text twitlight"><span class="text">CssMin.php</span></code>, respectively, and place them in your <code class="codecolorer text twitlight"><span class="text">application/libraries</span></code> folder.</p>
<h2>Create an asset_url() helper function</h2>
<p>Having a helper function to access your assets URL can be helpful in the event you decide to rename or change the location of your application. It works like the <code class="codecolorer text twitlight"><span class="text">base_url()</span></code> function, only it will link to your assets rather than your base URL (obviously). In <code class="codecolorer text twitlight"><span class="text">config.php</span></code>, add the following code:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">/*<br />
|--------------------------------------------------------------------------<br />
| Assets Path<br />
|--------------------------------------------------------------------------<br />
|<br />
| URL Path to static assets library<br />
|<br />
*/</span><br />
<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'asset_path'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'assets/'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'css_path'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'assets/css/'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'js_path'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'assets/js/'</span><span style="color: #339933;">;</span></div></div>
<p>We&#8217;ll be using <code class="codecolorer text twitlight"><span class="text">css_path</span></code> and <code class="codecolorer text twitlight"><span class="text">js_path</span></code> a little later in this tutorial, so keep those in mind.</p>
<p>Next, add this function in <code class="codecolorer text twitlight"><span class="text">/system/helpers/path_helper.php</span></code></p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009933; font-style: italic;">/**<br />
&nbsp;* Get asset URL<br />
&nbsp;*<br />
&nbsp;* @access&nbsp; public<br />
&nbsp;* @return&nbsp; string<br />
&nbsp;*/</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'asset_url'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span> &nbsp;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> asset_url<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//get an instance of CI so we can access our configuration</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$CI</span> <span style="color: #339933;">=&amp;</span> get_instance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//return the full asset path</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> base_url<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'asset_path'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Add the following to your <code class="codecolorer text twitlight"><span class="text">config/autoload.php</span></code> file, to helpers:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$autoload</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'helper'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'path'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Now you&#8217;re set! You can now call <code class="codecolorer text twitlight"><span class="text">asset_url()</span></code> anywhere to access your asset URL path. So instead of writing:</p>
<div class="codecolorer-container html4strict twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/assets/images/photo.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;A Photo&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></div></div>
<p>You would write instead:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> asset_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> images/photo.jpg&quot; alt=&quot;A Photo&quot; /&gt;</div></div>
<p>Now that that&#8217;s out of the way, let&#8217;s get to the good stuff:</p>
<h2>Create asset loader helper functions</h2>
<p>In order to reduce our HTTP requests for our scripts to a single call, we&#8217;ll need a script tag that does the call for all files in one <code class="codecolorer text twitlight"><span class="text">&lt;script&gt;</span></code>tag. In your <code class="codecolorer text twitlight"><span class="text">application/helpers</span></code> folder, create a new file called <code class="codecolorer text twitlight"><span class="text">asset_helper.php</span></code> and insert the following code:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> &nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BASEPATH'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access allowed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #009933; font-style: italic;">/**<br />
&nbsp;* Load JS<br />
&nbsp;* Creates the &lt;script&gt; tag that links all requested js files<br />
&nbsp;* @access&nbsp; public<br />
&nbsp;* @param &nbsp; array<br />
&nbsp;* @return&nbsp; string<br />
&nbsp;*/</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'load_js'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> load_js<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span> <span style="color: #000088;">$files</span><span style="color: #339933;">,</span> <span style="color: #000088;">$version</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//check if base url has a trailing slash, if not append it</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$base_url</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span>base_url<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'/'</span> ? base_url<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$files</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$index</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//replace all backslash occurrences with tilde (~) to avoid URI confusion (gets converted back later in controller)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$files</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$index</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_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;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'&lt;script type=&quot;text/javascript&quot; src=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$base_url</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'loader/js/'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'|'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$files</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$version</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;&lt;/script&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #009933; font-style: italic;">/**<br />
&nbsp;* Load CSS<br />
&nbsp;* Creates the &lt;link&gt; tag that links all requested css files<br />
&nbsp;* @access&nbsp; public<br />
&nbsp;* @param &nbsp; array<br />
&nbsp;* @return&nbsp; string<br />
&nbsp;*/</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'load_css'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> load_css<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span> <span style="color: #000088;">$files</span><span style="color: #339933;">,</span> <span style="color: #000088;">$version</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//check if base url has a trailing slash, if not append it</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$base_url</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span>base_url<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'/'</span> ? base_url<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$files</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$index</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//replace all backslash occurrences with tilde (~) to avoid URI confusion (gets converted back later in controller)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$files</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$index</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_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;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'&lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$base_url</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'loader/css/'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'|'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$files</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$version</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; /&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<br />
<span style="color: #666666; font-style: italic;">/* End of file asset_helper.php */</span><br />
<span style="color: #666666; font-style: italic;">/* Location: ./system/application/helpers/asset_helper.php */</span></div></div>
<p>These helpers will be used on pages that you need to load specific JS or CSS files. Usage would be:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$files_to_load</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'file1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'file2'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'file3'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//filenames WITHOUT the .js extension!</span><br />
<span style="color: #b1b100;">echo</span> load_js<span style="color: #009900;">&#40;</span><span style="color: #000088;">$files_to_load</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>You might want to also add this helper to your <code class="codecolorer text twitlight"><span class="text">autoload.php</span></code> file as well, just like the path helper above. Just add it to the array. </p>
<h2>Create a loader controller</h2>
<p>In order to actually load our asset files, we&#8217;ll need a controller that handles the concatentation and minification of the scripts and files. Create a new file in your <code class="codecolorer text twitlight"><span class="text">application/controllers</span></code> directory called <b>loader.php</b> with the following code:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #009933; font-style: italic;">/**<br />
&nbsp;* loader.php<br />
&nbsp;*/</span><br />
<br />
load_class<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'CSSMin'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
load_class<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'JSMin'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">class</span> Loader <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$asset_output</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$type</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$files</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$asset_path</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$ext</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$content_type</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$modified_time</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> Loader<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; parent<span style="color: #339933;">::</span><span style="color: #004000;">Controller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modified_time</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> js<span style="color: #009900;">&#40;</span><span style="color: #000088;">$files</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">type</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'js'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">files</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$files</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asset_path</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'js_path'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ext</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'.js'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content_type</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'text/javascript'</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_output<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> css<span style="color: #009900;">&#40;</span><span style="color: #000088;">$files</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">type</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'css'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">files</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$files</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asset_path</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'css_path'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ext</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'.css'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content_type</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'text/css'</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_output<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> _output<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$files_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;|&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">files</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$files_array</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//replace chars for folder separation, replace ~ with /</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_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;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asset_path</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$file</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ext</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asset_output</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asset_path</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$file</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ext</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modified_time</span> <span style="color: #339933;">=</span> <span style="color: #990000;">max</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">filemtime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asset_path</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$file</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ext</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;">modified_time</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//replace occurrences of /assets/ with asset_url()</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//$this-&gt;asset_output = str_replace(&quot;/assets/&quot;, asset_url(), $this-&gt;asset_output);</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">type</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'js'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asset_output</span> <span style="color: #339933;">=</span> JSMin<span style="color: #339933;">::</span><span style="color: #004000;">minify</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asset_output</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'css'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asset_output</span> <span style="color: #339933;">=</span> CSSMin<span style="color: #339933;">::</span><span style="color: #004000;">minify</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asset_output</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> LoaderException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Unknown file type.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//gzip</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_ACCEPT_ENCODING'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">stristr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_ACCEPT_ENCODING'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'gzip'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asset_output</span> <span style="color: #339933;">=</span> <span style="color: #990000;">gzencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asset_output</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-encoding: gzip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">stristr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_ACCEPT_ENCODING'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'deflate'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asset_output</span> <span style="color: #339933;">=</span> <span style="color: #990000;">gzdeflate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asset_output</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-encoding: deflate'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//headers</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content_type</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Last-modified: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'r'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modified_time</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Expires: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'r'</span><span style="color: #339933;">,</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">2592000</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-length: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asset_output</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asset_output</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">/* End of file loader.php */</span><br />
<span style="color: #666666; font-style: italic;">/* Location: ./system/application/controllers/loader.php */</span></div></div>
<p>And that&#8217;s it!</p>
<p>Usage examples:</p>
<p>Javascript:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> load_js<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jsfile1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'dir/jsfile2'</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">'jsfile3'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>CSS:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> load_css<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cssfile1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'dir/cssfile2'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cssfile3'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>To load files inside a directory, for example, <code class="codecolorer text twitlight"><span class="text">assets/js/plugins/example.js</span></code>, you would include <code class="codecolorer text twitlight"><span class="text">'plugins/example'</span></code> inside your the array as shown above.</p>
<p>If you update your css/js, you can use the option <code class="codecolorer text twitlight"><span class="text">$version</span></code> parameter. Simply use an incrementing integer value of your choice and the browser will read the file as a new file rather than loading the cached file.</p>
<p>Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://robotslacker.com/2010/11/dynamically-combine-and-minify-your-javascript-and-css-files-with-codeigniter/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Twitter Search API, tweet IDs, json_decode, &amp; bigint</title>
		<link>http://robotslacker.com/2010/11/twitter-search-api-tweet-ids-json_decode-bigint/</link>
		<comments>http://robotslacker.com/2010/11/twitter-search-api-tweet-ids-json_decode-bigint/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 06:07:18 +0000</pubDate>
		<dc:creator>calvin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://robotslacker.com/?p=20</guid>
		<description><![CDATA[Today I realized that my Tweet parsing application was saving a bunch of floating numbers as the status ID. After some investigation I realized that Twitter changed their id parameter in the Search API response to use a bigint . Since our data was returned using JSON, PHP&#8217;s native json_decode automatically converts the ID to [...]]]></description>
			<content:encoded><![CDATA[<p>Today I realized that my Tweet parsing application was saving a bunch of floating numbers as the status ID. After some investigation I realized that Twitter changed their</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">id</div></div>
<p>parameter in the Search API response to use a</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">bigint</div></div>
<p>. Since our data was returned using JSON, PHP&#8217;s native</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">json_decode</div></div>
<p>automatically converts the ID to a floating point value, like</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">1.0034070453002E+15</div></div>
<p>. Not cool.</p>
<p>If you are finding you&#8217;re having this problem when using</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">json_decode()</div></div>
<p>in general, and you&#8217;re running a development version of PHP 5.3+, you can use the bitmask</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">JSON_BIGINT_AS_STRING</div></div>
<p>in your</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">json_decode()</div></div>
<p>call to output any bigints as a string. </p>
<p>Example usage:</p>
<pre lang="php" escaped="true">
json_decode($json, false, 512, JSON_BIGINT_AS_STRING);
</pre>
<p>Anyway Twitter has now added an</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">id_str</div></div>
<p>field in the search response. So if you&#8217;re using PHP and you need to store or output the status ID, you should use this value instead:</p>
<pre lang="javascript" escaped="true">
{
    from_user_id_str: "52138619"
    profile_image_url: http://a3.twimg.com/profile_images/403904047/BC_color_logo_normal.jpg
    created_at: "Sat, 13 Nov 2010 03:00:56 +0000"
    from_user: "BCSportsNews"
    id_str: "3281128077139968"
    metadata: {
        result_type: "recent"
    }
    to_user_id: null
    text: "MSOC: North Carolina has defeated Boston College, 1-0, to advance to the ACC Championship game."
    id: 3281128077139968
    from_user_id: 52138619
    geo: null
    iso_language_code: "en"
    to_user_id_str: null
    source: "&lt;a href="http://twitter.com/"&gt;web&lt;/a&gt;"
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://robotslacker.com/2010/11/twitter-search-api-tweet-ids-json_decode-bigint/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I know what I&#8217;m going to be for Halloween next year</title>
		<link>http://robotslacker.com/2010/11/i-know-what-im-going-to-be-for-halloween-next-year/</link>
		<comments>http://robotslacker.com/2010/11/i-know-what-im-going-to-be-for-halloween-next-year/#comments</comments>
		<pubDate>Wed, 10 Nov 2010 04:50:55 +0000</pubDate>
		<dc:creator>calvin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://robotslacker.com/?p=15</guid>
		<description><![CDATA[A Daft Punk original to boot.]]></description>
			<content:encoded><![CDATA[<p><object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/_6Afc2uzw4g?fs=1&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/_6Afc2uzw4g?fs=1&amp;hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object></p>
<p>A Daft Punk original to boot.</p>
]]></content:encoded>
			<wfw:commentRss>http://robotslacker.com/2010/11/i-know-what-im-going-to-be-for-halloween-next-year/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A very useful snippet</title>
		<link>http://robotslacker.com/2010/11/a-very-useful-snippet/</link>
		<comments>http://robotslacker.com/2010/11/a-very-useful-snippet/#comments</comments>
		<pubDate>Mon, 01 Nov 2010 22:19:09 +0000</pubDate>
		<dc:creator>calvin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://robotslacker.com/?p=5</guid>
		<description><![CDATA[Ever catch yourself trying to deciper a var_dump() or a print_r() ? Just add the &#38;lt;pre&#38;gt; tag to it and all will make sense. echo '&#60;pre&#62;'; print_r($someVar); echo '&#60;/pre&#62;'; Enjoy!]]></description>
			<content:encoded><![CDATA[<p>Ever catch yourself trying to deciper a</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var_dump()</div></div>
<p>or a</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">print_r()</div></div>
<p>?</p>
<p>Just add the</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&amp;lt;pre&amp;gt;</div></div>
<p>tag to it and all will make sense.</p>
<pre lang="php" escaped="true">
echo '&lt;pre&gt;';
print_r($someVar);
echo '&lt;/pre&gt;';
</pre>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://robotslacker.com/2010/11/a-very-useful-snippet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

