<?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; CodeIgniter</title>
	<atom:link href="http://www.codr.eu/categories/tutorials/php/codeigniter/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>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>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>
