<?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>codr.eu &#187; Tutorials</title>
	<atom:link href="http://www.codr.eu/categories/tutorials/feed" rel="self" type="application/rss+xml" />
	<link>http://www.codr.eu</link>
	<description>dev screencasts &#38; tutorials</description>
	<lastBuildDate>Mon, 02 Nov 2009 21:41:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Podcast Coming Soon!</title>
		<link>http://www.codr.eu/podcast-coming-soon</link>
		<comments>http://www.codr.eu/podcast-coming-soon#comments</comments>
		<pubDate>Mon, 02 Nov 2009 21:41:45 +0000</pubDate>
		<dc:creator>Paul Chater</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.codr.eu/podcast-coming-soon</guid>
		<description><![CDATA[Coming soon to iTunes / iPod / this website near you!
The Codr.Eu Podcast
Myself, Phil Sturgeon and Adam Griffiths will be doing a podcast within the next few weeks, just to push out some content. We&#8217;ll also be looking to interview people, our main focus will be coding with CodeIgniter though. The point of the Podcast [...]]]></description>
			<content:encoded><![CDATA[<p>Coming soon to iTunes / iPod / this website near you!</p>
<h2>The Codr.Eu Podcast</h2>
<p>Myself, Phil Sturgeon and Adam Griffiths will be doing a podcast within the next few weeks, just to push out some content. We&#8217;ll also be looking to interview people, our main focus will be coding with CodeIgniter though. The point of the Podcast is for people to submit questions and have us answer them also for ourselves to give you guys updates on what&#8217;s going on within the coding world, so you could say coding news too. Also little tips and tricks (I&#8217;m sure Phil will rant on about his REST implementations alot <img src='http://www.codr.eu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ) anyway, just thought I would let you all know that there will be a podcast soon, and possibly! A new design for Codr when I get around to it&#8230; It&#8217;ll probably be Blue and Black like my current layout, but more tutorial site based <img src='http://www.codr.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.codr.eu/podcast-coming-soon/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using references in PHP: The Basics</title>
		<link>http://www.codr.eu/using-references-in-php-the-basics</link>
		<comments>http://www.codr.eu/using-references-in-php-the-basics#comments</comments>
		<pubDate>Sun, 23 Aug 2009 15:17:23 +0000</pubDate>
		<dc:creator>Phil Sturgeon</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.codr.eu/?p=198</guid>
		<description><![CDATA[This is the first post of a three part series that will explain what the hell reference variables (pointers) are and you can use them in your PHP projects.]]></description>
			<content:encoded><![CDATA[<p>This is the first post of a three part series that will explain what the hell reference variables (pointers) are and you can use them in your PHP projects.</p>
<p>To quote the PHP Manual &#8220;References in PHP are a means to access the same variable content by different names.&#8221; which I believe is a perfect explanation.  So, If you pass by reference instead of making a copy you are modifying the original variable. This is done by placing a single &#8220;&amp;&#8221; (ampersand) in front of the variable you are assigning.</p>
<p>The concept sounds a little strange at first, but lets take a look at the example.</p>
<pre class="brush:php; collsapse:true;">&lt;?php
// Create a variable.
$original_variable = 1;

// Create a reference to $original_variable
$ref_variable =&amp; $original_variable;

// Increment $ref_variable by 10
$ref_variable += 10;

// Output $original_variable
echo $original_variable; // Outputs "11"

// Decrement $original_variable by 5
$original_variable -= 5;

// Output $ref_variable
echo $ref_variable; // Outputs "6"

?&gt;</pre>
<p>I know what you are thinking&#8230; &#8220;what the hell?!&#8221; right? Ok, lets take that one a little slower.</p>
<pre class="brush:php; light:true;">// Create a variable.
$original_variable = 1;</pre>
<p>Just making avariable.</p>
<pre class="brush:php; light:true;">// Create a reference to $original_variable
$ref_variable =&amp; $original_variable;</pre>
<p>$ref_variable is now a &#8220;clone&#8221; or reference of $original_variable. Any modifications made to either will reflect in both variables as they are essentially the same variable with different names. The one exception to this rule is deleting. If you delete $ref_variable, $original_variable will still exist.</p>
<pre class="brush:php; light:true;">// Increment $ref_variable by 10
$ref_variable += 10;</pre>
<pre class="brush:php; light:true;">// Output $original_variable
echo $original_variable; // Outputs "11"</pre>
<p>This line will add 10 to $ref_variable which of course means the value of $original_variable will go up by 10.</p>
<pre class="brush:php; light:true;">// Increment $original_variable by 10
$original_variable -= 5;

// Output $ref_variable
echo $ref_variable; // Outputs "6"</pre>
<p>Finally we have a similar block of code. The purpose of this was to demonstrate that you can modify either variable to change them both. Changes to the $original_variable will reflect in $ref_variable as soon as they are made.</p>
<p>One thing to remember is that you can only create references to variables. That means any static strings, ints, floats, etc will throw an error.</p>
<pre class="brush:php; light:true;">&lt;?php
// Try and create a new reference:
$ref_variable =&amp; 10;
?&gt;</pre>
<p>That code will throw a syntax error like &#8220;Parse error: syntax error, unexpected T_LNUMBER, expecting T_NEW or T_STRING or T_VARIABLE or &#8216;$&#8217;&#8221;, to correct it the value should first be assigned to a variable and then a reference made to that variable.</p>
<p>There are plenty more uses for references, i&#8217;ll explain how to use them in foreach loops in the next post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codr.eu/using-references-in-php-the-basics/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to: Create a Twitter feed with full syntax support</title>
		<link>http://www.codr.eu/how-to-create-a-twitter-feed-with-full-syntax-support</link>
		<comments>http://www.codr.eu/how-to-create-a-twitter-feed-with-full-syntax-support#comments</comments>
		<pubDate>Tue, 28 Jul 2009 13:48:27 +0000</pubDate>
		<dc:creator>Phil Sturgeon</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[feeds]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[phil sturgeon]]></category>
		<category><![CDATA[pyrocms]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.codr.eu/?p=191</guid>
		<description><![CDATA[If you have a project that you would like to add a Twitter feed to, but do not want to add in a massive library for the one feed, take a look at this very simple PHP snippet that will give you full synatx support.]]></description>
			<content:encoded><![CDATA[<p>If you have a project that you would like to add a Twitter feed to, but do not want to add in a massive library for the one feed, try this little snippet of procedural code that I recently implemented on <a title="PyroCMS - a modular open source CodeIgniter CMS" href="pyrocms.com" target="_blank">pyrocms.com</a>.</p>
<h3>Expressions</h3>
<h4>Detect URL&#8217;s</h4>
<p>
<pre class="brush:php; light: true;"> '|([a-z]{3,9}://[a-z0-9-_./?&amp;+]*)|i' =&gt; '&lt;a href="$0" target="_blank"&gt;$0&lt;/a&gt;', </pre>
</p>
<h4>Detect E-mail addresses</h4>
<p>
<pre class="brush:php; light: true;"> '|[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,6}|i' =&gt; '&lt;a href="mailto:$0"&gt;$0&lt;/a&gt;', </pre>
</p>
<h4>Detect @usernames&#8217;s</h4>
<p>
<pre class="brush:php; light: true;"> '|@([a-z0-9-_]+)|i' =&gt; '&lt;a href="http://twitter.com/$1" target="_blank"&gt;$0&lt;/a&gt;', </pre>
</p>
<h4>Detect #tags</h4>
<p>
<pre class="brush:php; light: true;"> '|#([a-z0-9-_]+)|i' =&gt; '&lt;a href="http://twitter.com/search?q=#$1" target="_blank"&gt;$0&lt;/a&gt;' </pre>
</p>
<h3>Example</h3>
<p>Lets put this together to create a very simple working example.</p>
<pre class="brush:php;">&lt;?php
// Fetch the Tweets in JSON form and convert to a PHP object
$tweets = json_decode(file_get_contents('http://twitter.com/statuses/user_timeline/philsturgeon.json?count=10'));
// List all regular expression rules
$patterns = array(
			'|([a-z]{3,9}://[a-z0-9-_./?&#038;+]*)|i'		=> '<a href="$0" target="_blank">$0</a>', // Detect URL's
			'|[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,6}|i'	=> '<a href="mailto:$0">$0</a>', // Detect Email Addresses

			'|@([a-z0-9-_]+)|i'	=> '<a href="http://twitter.com/$1" target="_blank">$0</a>', 			// Detect Twitter @usernames
			'|#([a-z0-9-_]+)|i'	=> '<a href="http://twitter.com/search?q=#$1" target="_blank">$0</a>'	// Detect Twitter #tags
			);

// Loop through tweets
foreach($tweets as $tweet)
{
	// Run all rules to replace syntax with HTML
	$tweet->text = preg_replace(array_keys($patterns), array_values($replace), $tweet->text); 

	// Display the tweet with syntax enabled
	echo '

<strong>'.date('d/m/Y', strtotime($tweet->created_at)) . '</strong> ' . $tweet->text.'

';
}
?></pre>
<p>This is not following perfect coding practices, it will not cache data and might not be the most optimal implementation but I was trying to keep the amount of code low to show the simplicity of how it can be achieved.</p>
<p>Instead of showing a users timeline you can use the same code to show search results with the url:</p>
<blockquote>
<p>http://search.twitter.com/search.json?q=pyrocms</p>
</blockquote>
<p>Now, go forth and tweet!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codr.eu/how-to-create-a-twitter-feed-with-full-syntax-support/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a Javascript Content Slider with jQuery</title>
		<link>http://www.codr.eu/jquery-content-slider</link>
		<comments>http://www.codr.eu/jquery-content-slider#comments</comments>
		<pubDate>Wed, 24 Jun 2009 08:15:24 +0000</pubDate>
		<dc:creator>Paul Chater</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Screencasts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[-moz-box-shadow]]></category>
		<category><![CDATA[-webkit-box-shadow]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[paulchater]]></category>

		<guid isPermaLink="false">http://www.codr.eu/?p=106</guid>
		<description><![CDATA[So, earlier today in the CodrEu Chat Session I was sorting out my project iTask and also showing @PhilSturgeon my jQuery Content Slider on http://pchater.servehttp.com (the default). Anyway, I've been pondering for days on what to do my first Codr Screencast on and this is it!]]></description>
			<content:encoded><![CDATA[<p>So, earlier today in the CodrEu Chat Session I was sorting out my project iTask and also showing @PhilSturgeon my jQuery Content Slider on http://pchater.servehttp.com (the default). Anyway, I&#8217;ve been pondering for days on what to do my first Codr Screencast on and this is it!</p>
<h2>The Video</h2>
<h3>Part One</h3>
<p><object type="application/x-shockwave-flash" data="http://blip.tv/scripts/flash/showplayer.swf?enablejs=true&#038;file=http%3A//blip.tv/rss/flash/2290705&#038;feedurl=http%3A//codreu.blip.tv/rss/&#038;autostart=false&#038;brandname=CodrEu&#038;brandlink=http%3A//codreu.blip.tv/" width="640" height="480" allowfullscreen="true" id="showplayer"><param name="movie" value="http://blip.tv/scripts/flash/showplayer.swf?enablejs=true&#038;file=http%3A//blip.tv/rss/flash/2290705&#038;feedurl=http%3A//codreu.blip.tv/rss/&#038;autostart=false&#038;brandname=CodrEu&#038;brandlink=http%3A//codreu.blip.tv/" /><param name="quality" value="best" /></object></p>
<h3>Part Two</h3>
<p><object type="application/x-shockwave-flash" data="http://blip.tv/scripts/flash/showplayer.swf?enablejs=true&#038;file=http%3A//blip.tv/rss/flash/2290775&#038;feedurl=http%3A//codreu.blip.tv/rss/&#038;autostart=false&#038;brandname=CodrEu&#038;brandlink=http%3A//codreu.blip.tv/" width="640" height="480" allowfullscreen="true" id="showplayer"><param name="movie" value="http://blip.tv/scripts/flash/showplayer.swf?enablejs=true&#038;file=http%3A//blip.tv/rss/flash/2290775&#038;feedurl=http%3A//codreu.blip.tv/rss/&#038;autostart=false&#038;brandname=CodrEu&#038;brandlink=http%3A//codreu.blip.tv/" /><param name="quality" value="best" /></object></p>
<h2>The Code / Explaination</h2>
<h3>index.php &#8211; The Code</h3>
<pre class="brush: html; collapse: true;">
&lt;html>
	&lt;head>
		&lt;title>jQueryness&lt;/title>
<link rel="stylesheet" type="text/css" media="screen, projector" href="style.css">
		<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
		<script type="text/javascript" src="function.js"></script>
</link>

	<body>
<div id="wrapper">
<h1>jQueryness</h1>

			<!-- Start the navigation block -->
			<code>
				<a href="#" id="navItem1">box1</a> |
				<a href="#" id="navItem2">box2</a> |
				<a href="#" id="navItem3">box3</a>
			</code>
			<!-- End the navigation block -->
<div class="box1">
				Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent vel massa massa, sit amet laoreet elit. Praesent porttitor pharetra dui,
				quis fringilla justo luctus ac. Duis convallis, dui non facilisis mollis, ipsum diam sodales nisl, vel tincidunt ipsum augue vel lacus.
				Fusce a urna eu lectus mattis placerat. Vestibulum eget urna quis sem rhoncus blandit in vel massa. Nullam in tortor eget sem rhoncus
				consequat vel nec metus. Maecenas vehicula, diam vitae dictum blandit, ante mauris faucibus orci, id ornare erat ligula ac arcu. Nulla
				facilisi. Suspendisse imperdiet feugiat eros, porta lacinia nibh consectetur at. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
				Suspendisse et felis lorem. Praesent vitae nulla risus, eu rhoncus quam.
			</div>
<div class="box2">
				Praesent eget nisl sed sem cursus semper. Donec ut elit a orci feugiat vulputate. Integer posuere sagittis lobortis. Integer pulvinar dictum libero.
				Integer ac velit quam, id dapibus felis. Vestibulum tempor aliquet ligula euismod accumsan. Etiam dapibus ultricies orci, vitae consequat purus venenatis
				vel. Curabitur vestibulum massa ac nisl venenatis posuere. Curabitur dictum metus eget velit congue fermentum. Duis quis quam in urna sollicitudin egestas
				ut vel urna. Suspendisse bibendum sodales pulvinar. Sed a quam nisl, non lacinia erat. Duis pellentesque tincidunt scelerisque. In sed felis at arcu tristique
				semper nec et purus. Ut suscipit semper accumsan. Curabitur tempor sem nec sapien suscipit porta. Donec eget urna nunc, ac bibendum nunc. Quisque congue pellentesque
				arcu nec aliquet. Morbi in mi eget ipsum egestas sagittis.
			</div>
<div class="box3">
				Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent vel massa massa, sit amet laoreet elit. Praesent porttitor pharetra dui,
				quis fringilla justo luctus ac. Duis convallis, dui non facilisis mollis, ipsum diam sodales nisl, vel tincidunt ipsum augue vel lacus.
				Fusce a urna eu lectus mattis placerat.
			</div>
</div>

	&lt;/body>
&lt;/html>
</body></pre>
<h3>index.php &#8211; The Explaination</h3>
<p>Okay lets get down to the explaination of index. First we declared the DOCTYPE of </p>
<pre class="brush: html; light: true;">< !DOCTYPE HTML></pre>
<p>we do this so that W3C can validate your page and so that it knows automatically what version of HTML you&#8217;re rusing. This doctype is mainly for HTML5. After that we then opened up our html, head and title tags and inserted the title of jQueryness we then referenced the jquery-1.3.2.min.js from Google Code and our function.js file with </p>
<pre class="brush: html;">
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="function.js"></script>
</pre>
<p>We then closed off our head then opened our body and inserted a new div with the id of wrapper, this is the element which stands out with its CSS3 Specification Drop Shadow</p>
<pre class="brush: html; light:">
<div id="wrapper">
...
</div>
</pre>
<p>after opening the wrapper we decided to put in a heading with our main title in then opened a code tag so that we can link our content boxes with:</p>
<pre class="brush: html;"><code>
<a href="#" id="navItem1">box1</a> |
<a href="#" id="navItem2">box2</a> |
<a href="#" id="navItem3">box3</a>
</code>
</pre>
<p>then finally we created our content boxes with the classes of box1, box2, box3 with the following:</p>
<pre class="brush: html;">
<div class="box1">
...
</div>
<div class="box2">
...
</div>
<div class="box3">
...
</div>
</pre>
<h3>style.css &#8211; The Code &#038; Explaination (in comments)</h3>
<pre class="brush: css; collapse: true;">
/*
 * Define the MAIN background colour, default margin, fonts
 * text colour etcetera.
 */
body {
	background-color: #efefef;
	margin: 40px auto;
	font: 10pt "Lucida Grande", "Trebuchet MS", sans-serif;
	color: #777777;
}

/*
 * Make the wrapper look pretty, center it on the page, make sure
 * that it's no thicker than 500 pixels with some padding, let it have
 * a nice subtle solid dark gray border with a drop shadow
 * 3 pixels from the right, 3 pixels from the bottom and 1 pixel in weight
 * with another subtle gray.
 */
#wrapper {
	margin: 0 auto;
	background-color: #ffffff;
	border: 1px solid #bababa;
	width: 500px;
	padding: 0 15px 10px 15px;
	-moz-box-shadow: 3px 3px 1px #dadada;
	-webkit-box-shadow: 3px 3px 1px #dadada;
}

/*
 * Set a the main font to be a fixed width font such as Monaco
 * with the background of off white, border of dark gray, and font
 * colour of black. Set the margins 14 pixels from the top and bottom
 * Provide a little bit of padding as well so the content looks nice.
 */
code {
	font: 12px Monaco, "Lucida Console", small-fonts;
	background-color: #f9f9f9;
	border: 1px solid #D0D0D0;
	color: #000000;
	display: block;
	margin: 14px 0 14px 0;
	padding: 12px 10px 12px 10px;
}

/*
 * Set the main content boxes display
 * to none so that they're hidden on
 * page load.
 */
.box1, .box2, .box3 {
	display: none;
}</pre>
<h3>function.js &#8211; The Code &#038; Explaination (in comments)</h3>
<pre class="brush: js; collapse: true;">
/*
 * When the document is ready then hide box2 and 3 but show box1.
 */
$(document).ready(function() {
	$("div .box1").show();
	$("div .box2").hide();
	$("div .box3").hide();

/*
 * If the link with the id of navItem is clicked then make
 * relevent box slide down in the duration of 0.6 seconds.
 * Also ensure that the other boxes are hidden.
 */
	$("#navItem1").click(function() {
		$("div .box1").slideDown(600);
		$("div .box2").hide();
		$("div .box3").hide();
	});

	$("#navItem2").click(function() {
		$("div .box2").slideDown(600);
		$("div .box1").hide();
		$("div .box3").hide();
	});

	$("#navItem3").click(function() {
		$("div .box3").slideDown(600);
		$("div .box2").hide();
		$("div .box1").hide();
	});

});</pre>
<h2>The Download</h2>
<div id="download"><a href='http://www.codr.eu/wp-content/uploads/2009/06/jqueryness.zip'><img src="./wp-content/themes/codr/images/download.png" width="128" height="128" border=0 /></a><a href='http://www.codr.eu/wp-content/uploads/2009/06/jqueryness.zip'>jQueryness.zip</a></div>
<h2>Final Words</h2>
<p>Thank you for reading this tutorial and I hope that you find it quite useful, if you have any questions please don&#8217;t hesitate to leave a comment below when the comments get enabled, If they still aren&#8217;t enabled then please email webmaster [ at ] paulchater.co.uk</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codr.eu/jquery-content-slider/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to: Multi-site CodeIgniter Set-up</title>
		<link>http://www.codr.eu/multi-site-codeigniter-set-up</link>
		<comments>http://www.codr.eu/multi-site-codeigniter-set-up#comments</comments>
		<pubDate>Tue, 23 Jun 2009 18:19:38 +0000</pubDate>
		<dc:creator>Phil Sturgeon</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.codr.eu/?p=93</guid>
		<description><![CDATA[In last nights Coder.eu chat session a few people suggested they would like to see a tutorial showing how to run CodeIgniter on multiple sites from the same code-base. Read this tutorial to find out how.]]></description>
			<content:encoded><![CDATA[<p>In last nights <a href="http://tinychat.com/codreu">Coder.eu chat</a> session a few people suggested they would like to see a tutorial showing how to run CodeIgniter on multiple sites from the same code-base.</p>
<p>To get this working I took a little code from <a href="http://pyrocms.com/" target="_blank">PyroCMS</a> and modded a previous article &#8220;<a href="news/2009/01/How-to-Support-multiple-production-environments-in-CodeIgniter.html">How to: Support multiple production environments in CodeIgniter</a>&#8221; and found a relatively simple solution.</p>
<h2>Setting the base URL</h2>
<p>The first step of getting CodeIgniter working anywhere automatically is curing it of it&#8217;s most pointless configuration setting. It seems CodeIgniter would like to be told where it is, which really doesn&#8217;t need to happen. We could solve this in many ways, but instead of extending or replacing any core code, I would preffer to put a little snippet of code into the main application/config/config.php. Enter this code into the file and it will automatically support pretty much any kind of URL.</p>
<pre class="brush: php; collapse: true;">/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://www.your-site.com/
|
*/

if(isset($_SERVER['HTTP_HOST']))
{
$config['base_url'] = isset($_SERVER['HTTPS']) &amp;&amp; strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';
$config['base_url'] .= '://'. $_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
}

else
{
$config['base_url'] = 'http://localhost/';
}</pre>
<h2>Setting a SITE constant</h2>
<p>So the website URL is now set and links are fully working around the site. Next we need a way to work out throughout our code which site is currently being used. Amongst other things, this will help us with selecting the right database settings later.</p>
<pre class="brush: php; collapse: true;">
/*
|--------------------------------------------------------------------------
| Site
| Set a constant for whichever site you happen to be running, if its not here
| it will fatal error.
|--------------------------------------------------------------------------
*/
switch($_SERVER['HTTP_HOST'])
{
case 'example.com':
case 'www.example.com':
define('SITE', 'example');
break;

case 'example2.com':
case 'www.example2.com':
define('SITE', 'example2');
break;

default:
define('SITE', 'default');
break;
}
</pre>
<h2>Domain based database settings</h2>
<p>Now that CodeIgniter has its links working and it knows what site it is trying to run, it needs to know the database configuration for this domain. To do that, we can break down our config into domain specific &#8220;Database groups&#8221;.</p>
<pre class="brush: php; collapse: true;">
< ?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| DATABASE CONNECTIVITY SETTINGS
| -------------------------------------------------------------------
| This file will contain the settings needed to access your database.
|
| For complete instructions please consult the "Database Connection"
| page of the User Guide.
|
| -------------------------------------------------------------------
| EXPLANATION OF VARIABLES
| -------------------------------------------------------------------
|
| ['hostname'] The hostname of your database server.
| ['username'] The username used to connect to the database
| ['password'] The password used to connect to the database
| ['database'] The name of the database you want to connect to
| ['dbdriver'] The database type. ie: mysql.  Currently supported:
     mysql, mysqli, postgre, odbc, mssql
| ['dbprefix'] You can add an optional prefix, which will be added
|     to the table name when using the  Active Record class
| ['pconnect'] TRUE/FALSE - Whether to use a persistent connection
| ['db_debug'] TRUE/FALSE - Whether database errors should be displayed.
| ['active_r'] TRUE/FALSE - Whether to load the active record class
| ['cache_on'] TRUE/FALSE - Enables/disables query caching
| ['cachedir'] The path to the folder where cache files should be stored
|
| The $active_group variable lets you choose which connection group to
| make active.  By default there is only one group (the "default" group).
|
*/

$active_record = TRUE;

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "";
$db['default']['password'] = "";
$db['default']['database'] = "";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";

// example
$db['example']['hostname'] = "localhost";
$db['example']['username'] = "root";
$db['example']['password'] = "";
$db['example']['database'] = "example";
$db['example']['dbdriver'] = "mysql";
$db['example']['dbprefix'] = "";
$db['example']['active_r'] = TRUE;
$db['example']['pconnect'] = TRUE;
$db['example']['db_debug'] = TRUE;
$db['example']['cache_on'] = FALSE;
$db['example']['cachedir'] = "";
$db['example']['char_set'] = "utf8";
$db['example']['dbcollat'] = "utf8_general_ci";

// Example 2
$db['example2']['hostname'] = "localhost";
$db['example2']['username'] = "root";
$db['example2']['password'] = "root";
$db['example2']['database'] = "testfoo";
$db['example2']['dbdriver'] = "mysql";
$db['example2']['dbprefix'] = "";
$db['example2']['active_r'] = TRUE;
$db['example2']['pconnect'] = TRUE;
$db['example2']['db_debug'] = TRUE;
$db['example2']['cache_on'] = FALSE;
$db['example2']['cachedir'] = "";
$db['example2']['char_set'] = "utf8";
$db['example2']['dbcollat'] = "utf8_general_ci";

// Check the configuration group in use exists, if not use the default
$active_group = (defined('SITE') &#038;&#038; array_key_exists(SITE, $db)) ? SITE : 'default';

?>
</pre>
<p>The little snippet of code at the bottom will check to see if the SITE constant you have set matches up with a database group. If it doesn&#8217;t, it will use the default configuration group.</p>
<p>Your CodeIgniter set-up should now work with any domain you happen to point to it. You even run simple little
<pre class="brush: php; light: true;"> if(SITE == 'example2')</pre>
<p> checks anywhere within your code to do special code for a certian site, although I would not reccomend you doing this too heavily.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codr.eu/multi-site-codeigniter-set-up/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>CodeIgniter&#8217;s Hidden Gems</title>
		<link>http://www.codr.eu/codeigniters-hidden-gems</link>
		<comments>http://www.codr.eu/codeigniters-hidden-gems#comments</comments>
		<pubDate>Wed, 17 Jun 2009 18:50:09 +0000</pubDate>
		<dc:creator>Jamie Rumbelow</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.codr.eu/?p=86</guid>
		<description><![CDATA[I&#8217;ve been programming with CodeIgniter for nearly two years now (gosh, is it that long?), and still I keep on finding little treasures buried deep within the framework, long standing there just waiting for someone to discover them.
I&#8217;ve compiled a nice, long list of CodeIgniter&#8217;s hidden secrets full of little helpful snippets, concealed functions and [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been programming with CodeIgniter for nearly two years now (gosh, is it that long?), and still I keep on finding little treasures buried deep within the framework, long standing there just waiting for someone to discover them.</p>
<p>I&#8217;ve compiled a nice, long list of CodeIgniter&#8217;s hidden secrets full of little helpful snippets, concealed functions and long-unused classes to help you get the most out of the framework.</p>
<h2>The Database Forge</h2>
<p>CodeIgniter&#8217;s database class goes much further than the simple ActiveRecord system. It&#8217;s an extremely powerful tool, and includes the database forge class. This is rarely used &#8211; many seem to skip over this documentation section and onto the more promising ActiveRecord class, but this can be really helpful &#8211; especially if you need to create, edit and delete actual databases.</p>
<p>You can load the database forge class using a variant of the standard CodeIgniter loading convention.</p>
<pre class="brush: php; light: true;">$this-&gt;load-&gt;dbforge();</pre>
<p>And then call options on it by using the &#8220;dbforge&#8221; variable.</p>
<pre class="brush: php; light: true;">//Create a database called 'users'
$this-&gt;dbforge-&gt;create_database('users');</pre>
<p>You can find out more about the database forge class at the user guide page, found here.</p>
<h2>auto_typography();</h2>
<p>One of the most useful functions, and yet often unheard of inside CodeIgniter is auto_typography(), residing in the seldom used typography helper. This helpful function converts double-line breaks to paragraphs, single line breaks to<br />
tags, quote tags to typographically correct curly quotes and apostrophes, double dashes to em dashes and a few other things to make your text semantically and typographically correct.</p>
<p>It&#8217;s usage is simple:</p>
<pre class="brush: php">//Load the typography helper
$this-&gt;load-&gt;helper('typography');

//Convert some text
$converted_text = auto_typography($original_text);</pre>
<p>It takes two parameters, the string to convert and a boolean value stating if to shorten more than two line breaks down to two. This defaults to FALSE. This is a great function, but can be pretty processor intensive, especially when you are parsing large quantities of text, so it&#8217;s a good idea to cache your pages.</p>
<h2>CodeIgniter Page Caching</h2>
<p>Which brings me perfectly onto my next point, page caching! A post made last year by one of my CodeIgniter all-star brethren (term coined by Michael Wales, circa 2008.), Elliot Haughin benchmarks different caching mechanisms and proves that CodeIgniter&#8217;s basic caching solution deserves much more credit then it gets.</p>
<p>CodeIgniter&#8217;s caching solution is primitive at heart, but works extremely well and is very easy to set up and use. It&#8217;s often unused because people go for other alternatives such as Memcache or APC, both great caching systems, but CodeIgniter&#8217;s is fine when all you need is simple page caching.</p>
<p>The caching system is built into the output class, which is automatically instantiated by the system, so you don&#8217;t need to load it. There is only one function required to set the cache &#8211; and the system handles the rest. You can place it anywhere in the controller function you want to cache &#8211; the order is irrelevant. You simply pass the function the number of minutes you want to cache the function for.</p>
<pre class="brush: php; light: true;">$this-&gt;output-&gt;cache(60); // 60 mins = 1 hour</pre>
<p>Combine CodeIgniter&#8217;s solution with a caching system such as Memcache, APC or EAccelerator, and you can greatly improve your web application&#8217;s speed. Read more about CodeIgniter&#8217;s caching system, yet again on the user guide.</p>
<h2>url_title();</h2>
<p>Favourite of blogging engines CodeIgniter-wide, url_title(), a wee function hiding in the depths of the URL helper takes a string and converts it into a URL friendly string. This is commonly used when creating a slug for a page &#8211; it will turn the string &#8220;CodeIgniter is Awesome&#8221; into &#8220;codeigniter-is-awesome&#8221;, &#8220;Woo! Mama! Hot-diggedy Damn!&#8221; into &#8220;woo-mama-hot-diggedy-damn&#8221; and so forth.</p>
<h2>send_email(); &amp; CodeIgniter&#8217;s Email Class</h2>
<p>If you want to send an email, using basic settings via PHP&#8217;s mail() function, you can use this sweet little function. Simply pass it the recipient, the subject and the message and it will send the email. This is great if you want to send a quick log message for instance, but if you need more flexibility and power you should check out the Email library.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codr.eu/codeigniters-hidden-gems/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Build your own VPS in the cloud</title>
		<link>http://www.codr.eu/build-your-own-vps-in-the-cloud</link>
		<comments>http://www.codr.eu/build-your-own-vps-in-the-cloud#comments</comments>
		<pubDate>Mon, 15 Jun 2009 23:15:15 +0000</pubDate>
		<dc:creator>Phil Sturgeon</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Screencasts]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.codr.eu/?p=36</guid>
		<description><![CDATA[After getting fed up with a clunky old VPS running a borked copy of CentOS 5 I decided I wanted more control, a better OS, cheaper running costs and better reliability. Watch my screencast on how to set up an Ubuntu 8.04 cloud web server to serve your content over the web.]]></description>
			<content:encoded><![CDATA[<p>After getting fed up with a clunky old VPS running a borked copy of CentOS 5 I decided I wanted more control, a better OS, cheaper running costs and better reliability. Watch my screencast on how to set up an Ubuntu 8.04 cloud web server to serve your content over the web.</p>
<p>I looked into a few options and decided on <a href="http://mosso.com" target="_blank">Mosso</a> to be my cloud server providers. This comes down to many reason: they are cheap, they are a Rackspace company so they are running <em><span style="text-decoration: underline;">very</span></em> reliable hardware and they recently absorbed Slicehost, so you know their control panels are good.</p>
<p>With my hosting providers found, I had to pick my software. I decided to use <a href="http://virtualmin.com" target="_blank">Virtualmin</a> as there is a free alternative that does basically everything you need from a VPS GUI and saves me the cost of paying for cPanel/WHM.</p>
<p>This decision restricted my choice of Operating System a little, as sadly the newest version of Ubuntu that Virtualmin supports is 8.04 LTS. Thats good enough for me, and LTS means more applications will worry about supporting it.</p>
<p>Anyhow, enough of that. Time to see my slightly drunken screencast in action.</p>
<h3>Part 1</h3>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="651" height="362" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://blip.tv/play/g7lmgYLRAJeDBA.m4v" /><embed type="application/x-shockwave-flash" width="651" height="362" src="http://blip.tv/play/g7lmgYLRAJeDBA.m4v"></embed></object></p>
<h3>Part 2</h3>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="653" height="364" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://blip.tv/play/g7lmgYLRQZeDBA.m4v" /><embed type="application/x-shockwave-flash" width="653" height="364" src="http://blip.tv/play/g7lmgYLRQZeDBA.m4v"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codr.eu/build-your-own-vps-in-the-cloud/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Access CodeIgniter helpers from Smarty templates</title>
		<link>http://www.codr.eu/access-codeigniter-helpers-from-smarty-templates</link>
		<comments>http://www.codr.eu/access-codeigniter-helpers-from-smarty-templates#comments</comments>
		<pubDate>Mon, 15 Jun 2009 22:44:24 +0000</pubDate>
		<dc:creator>Phil Sturgeon</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.codr.eu/?p=25</guid>
		<description><![CDATA[Smarty by default has lots of useful functions - or modifiers - to help you modify your Smarty variables. Using this modifier, you can access any CodeIgniter helper in your view files.]]></description>
			<content:encoded><![CDATA[<p>This article assumes you already have Smarty parsing your CodeIgniter views. If you have not done this, you can find out <a href="http://devcha.blogspot.com/2007/12/smarty-as-template-engine-in-code.html" target="_blank">how to integrate Smarty with CodeIgniter here</a>.</p>
<p>To access your CodeIgniter helpers from Smarty, all you need to do is make a new file in your &#8220;plugins/&#8221; directory called &#8220;helper.modifier.php&#8221; and paste in the following code:</p>
<pre class="brush: php; gutter: true">
&lt;?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File:     modifier.helper.php
* Type:     modifier
* Name:     helper
* Purpose:  Call CodeIgniter helpers from within Smarty.
* -------------------------------------------------------------
*/
function smarty_modifier_helper($string, $helper_file, $helper_func)
{
if (!function_exists(&quot;get_instance&quot;)) {
return &quot;Can't get CI instance&quot;;
}

if (!function_exists($helper_func)) {
$CI =&amp; get_instance();
$CI-&gt;load-&gt;helper($helper_file);
}

// Get all the params passed in as there might be a few
$params = func_get_args();

// String provided should be the first param and we dont want helper file or helper func being passed
$params[0] = $string;
unset($params[1]);

// Call the function with the params provided
return call_user_func_array($helper_func, array_values($params));
}
?&gt;
</pre>
<p>Save that and try it out in one of your Smarty controlled view files. For example:</p>
<pre class="brush:html; light: true">&lt;p&gt;Check out this amazing item&lt;/p&gt; <em>{$item.url|helper:'url':'anchor':$item.title:'class="more params"'}</em></pre>
<p>With Smarty modifiers, the item you are modifying is the first param. The modifier is called after a pipe character &#8220;|&#8221; and then more parameters are separated by “:”. With this specific modifier, you list the helper, then the helper function, then as many params afterwards as you like.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codr.eu/access-codeigniter-helpers-from-smarty-templates/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
