<?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>Feelinc.Me &#187; codeigniter</title>
	<atom:link href="http://www.feelinc.me/tag/codeigniter/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.feelinc.me</link>
	<description>It&#039;s All About Me</description>
	<lastBuildDate>Tue, 24 Aug 2010 21:46:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Create a WordPress Options Panel Using CodeIgniter</title>
		<link>http://www.feelinc.me/experience/create-a-wordpress-options-panel-using-codeigniter/</link>
		<comments>http://www.feelinc.me/experience/create-a-wordpress-options-panel-using-codeigniter/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 11:53:05 +0000</pubDate>
		<dc:creator>Feelinc</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Experience]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[create]]></category>
		<category><![CDATA[options]]></category>
		<category><![CDATA[panel]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.feelinc.me/?p=232</guid>
		<description><![CDATA[The first thing that we all think about when we want to start to create a WordPress Options Panel is the code structure. How the code structure is quite clean and easy to enhance. WordPress is one of the most popular Content Management Software (CMS) systems out there.So how we would like integrate CodeIgniter into [...]]]></description>
			<content:encoded><![CDATA[<p>The first thing that we all think about when we want to start to create a WordPress Options Panel is the code structure. How the code structure is quite clean and easy to enhance.<br />
WordPress is one of the most popular Content Management Software (CMS) systems out there.So how we would like integrate CodeIgniter into our WordPress Options Panel.<br />
As you already know that CodeIgniter is the popular PHP Framework, which is easy to use and quite light.<br />
So today, let me guide you through the integration process of CodeIgniter into WordPress.<span id="more-232"></span></p>
<h3>Step 1</h3>
<p>Download the CodeIgniter source code from <a href="http://codeigniter.com/" target="_blank">CodeIgniter Official Site</a> and extract it. Now we go  into your WordPress default theme folder and create some folder structures :</p>
<p>default/<br />
&#8211; ctrl/<br />
&#8212;&#8211; config/<br />
&#8212;&#8211; controllers/<br />
&#8212;&#8211; errors/<br />
&#8212;&#8211; libraries/<br />
&#8212;&#8211; models/<br />
&#8212;&#8211; system/<br />
&#8212;&#8212;&#8211; helpers/<br />
&#8212;&#8212;&#8211; codeigniter/<br />
&#8212;&#8212;&#8211; helpers/<br />
&#8212;&#8212;&#8211; libraries/<br />
&#8212;&#8211; views</p>
<h3>Step 2</h3>
<p>Copy all needed files from CodeIgniter source code into your previously created folders with this following steps :</p>
<ul>
<li>Copy autoload.php, config.php, constants.php, database.php, and routes.php files from system/application/config into default/ctrl/config.</li>
<li>Copy all files in system/application/errors into default/ctrl/errors.</li>
<li>Copy all files in system/codeigniter inti default/ctrl/system/codeigniter.</li>
<li>Copy url_helper.php file from system/helpers into default/ctrl/system/helpers.</li>
<li>Copy Benchmark.php, Config.php, Controller.php, Exceptions.php, Hooks.php, Input.php, Loader.php, Language.php, Model.php, Output.php, Router.php and URI.php files from system/libraries into default/ctrl/system/libraries.</li>
</ul>
<h3>Step 3</h3>
<p>Now we are going to edit and customize the needed files:</p>
<h4>default/ctrl/config/autoload.php</h4>
<p>Put the url helper into something like this</p>
<pre class="brush: plain;">
$autoload['helper'] = array('url');
</pre>
<h4>default/ctrl/config/config.php</h4>
<p>Edit your base url into something like this</p>
<pre class="brush: plain;">
$config['base_url'] = get_option('siteurl') . '/wp-admin/';
</pre>
<p>Edit the uri protocol into something like this</p>
<pre class="brush: plain;">
$config['uri_protocol']	= &quot;QUERY_STRING&quot;;
</pre>
<p>Enable the query strings into something like this</p>
<pre class="brush: plain;">
$config['enable_query_strings'] = TRUE;
</pre>
<h4>default/ctrl/config/database.php</h4>
<p>Empty this file and you can use this file later for table installer purpose for your theme.</p>
<h4>default/ctrl/config/routes.php</h4>
<p>Edit the default controller into something like this</p>
<pre class="brush: plain;">
$route['default_controller'] = &quot;noop&quot;;
</pre>
<h4>default/ctrl/system/codeigniter/CodeIgniter.php</h4>
<p>Put below code on line 29 to make the Output library working</p>
<pre class="brush: plain;">
global $BM, $CFG;
</pre>
<p>Remove the &#8220;&amp;&#8221; symbol when loading the Benchmark class into something like this</p>
<pre class="brush: plain;">
$BM = load_class('Benchmark');
</pre>
<p>Remove the &#8220;&amp;&#8221; symbol when loading the Config class into something like this</p>
<pre class="brush: plain;">
$CFG = load_class('Config');
</pre>
<p>Disable CodeIgniter code to check the DB connection into something like this</p>
<pre class="brush: plain;">
/*if (class_exists('CI_DB') AND isset($CI-&gt;db))
{

	$CI-&gt;db-&gt;close();
}*/
</pre>
<h4>default/ctrl/system/libraries/Router.php</h4>
<p>Change uri string fetched by CodeIgniter by putting below code on line 94</p>
<pre class="brush: plain;">
$n_query_string = strpos($this-&gt;uri-&gt;uri_string, '&amp;amp;');
if ($n_query_string &gt; 0)
{
	$this-&gt;uri-&gt;uri_string = substr($this-&gt;uri-&gt;uri_string, 0, $n_query_string);
}
$this-&gt;uri-&gt;uri_string = '/'.str_replace('page=', '', $this-&gt;uri-&gt;uri_string);
</pre>
<h4>default/functions.php</h4>
<p>Put below code at the end of functions.php file</p>
<pre class="brush: plain;">
&lt;?php
/*
|---------------------------------------------------------------
| SYSTEM FOLDER NAME
|---------------------------------------------------------------
|
| NO TRAILING SLASH!
|
*/
	$system_folder = str_replace('\\', '/', dirname(__FILE__)) . &quot;/ctrl/system&quot;;

/*
|---------------------------------------------------------------
| APPLICATION FOLDER NAME
|---------------------------------------------------------------
|
| NO TRAILING SLASH!
|
*/
	$application_folder = str_replace('\\', '/', dirname(__FILE__)) . &quot;/ctrl&quot;;

/*
|===============================================================
| END OF USER CONFIGURABLE SETTINGS
|===============================================================
*/

/*
|---------------------------------------------------------------
| SET THE SERVER PATH
|---------------------------------------------------------------
|
*/
if (strpos($system_folder, '/') === FALSE)
{
	if (function_exists('realpath') AND @realpath(dirname(__FILE__)) !== FALSE)
	{
		$system_folder = realpath(dirname(__FILE__)).'/'.$system_folder;
	}
}
else
{
	// Swap directory separators to Unix style for consistency
	$system_folder = str_replace(&quot;\\&quot;, &quot;/&quot;, $system_folder);
}

/*
|---------------------------------------------------------------
| DEFINE APPLICATION CONSTANTS
|---------------------------------------------------------------
|
| EXT		- The file extension.  Typically &quot;.php&quot;
| SELF		- The name of THIS file (typically &quot;index.php&quot;)
| FCPATH	- The full server path to THIS file
| BASEPATH	- The full server path to the &quot;system&quot; folder
| APPPATH	- The full server path to the &quot;application&quot; folder
|
*/
define('EXT', '.php');
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
define('FCPATH', str_replace(SELF, '', __FILE__));
define('BASEPATH', $system_folder.'/');

if (is_dir($application_folder))
{
	define('APPPATH', $application_folder.'/');
}
else
{
	if ($application_folder == '')
	{
		$application_folder = 'ctrl';
	}

	define('APPPATH', BASEPATH.$application_folder.'/');
}

/*
|---------------------------------------------------------------
| LOAD THE FRONT CONTROLLER
|---------------------------------------------------------------
|
| And away we go...
|
*/

/*
 * ------------------------------------------------------
 *  Load the framework constants
 * ------------------------------------------------------
 */
require_once(APPPATH . 'config/constants' . EXT);

function my_theme_admin()
{
	require_once(ABSPATH . '/wp-admin/includes/plugin' . EXT);

	require_once(APPPATH . 'config/config' . EXT);
	require_once(APPPATH . 'config/database' . EXT);
}

function my_theme_noop()
{
	require_once BASEPATH.'codeigniter/CodeIgniter'.EXT;
}

add_action('admin_menu', 'my_theme_admin');
?&gt;
</pre>
<p>Now all the CodeIgniter customization are done and you are ready to go to the next step.</p>
<h3>Step 4</h3>
<p>Now create the theme options menu by editing your ctrl/config/config.php file and put below code on line 2.</p>
<pre class="brush: plain;">
/*
|--------------------------------------------------------------------------
| MENU
|--------------------------------------------------------------------------
*/
if (function_exists('add_object_page'))
{
	add_object_page('My Theme Options', 'My Theme Options', 'edit_themes', 'my_theme_controller', 'my_theme_noop');
	add_submenu_page('my_theme_controller', 'Other Options', 'Other Options', 'edit_themes', 'another_theme_controller', 'my_theme_noop');
}
</pre>
<p>If you refresh your administration panel&#8217;s plugin page, you will now see that you have two additional menus on the sidebar.</p>
<p style="text-align: center;clear;both;"><a href="http://www.feelinc.me/wp-content/uploads/2010/03/menu-panel.jpg"><img class="aligncenter size-medium wp-image-259" title="menu-panel" src="http://www.feelinc.me/wp-content/uploads/2010/03/menu-panel-300x141.jpg" alt="" width="300" height="141" /></a></p>
<h3>Step 5</h3>
<p>Now you need to create three controller files</p>
<h4>noop.php</h4>
<pre class="brush: plain;">
&lt;?php

class Noop
{

function Noop()
{}

function index()
{}
}
</pre>
<h4>my_theme_controller.php</h4>
<pre class="brush: plain;">
&lt;?php

class My_theme_controller extends Controller
{

	function My_theme_controller()
	{
		parent::Controller();
	}

	function index()
	{
		echo $this-&gt;load-&gt;view('my_view', array(
			'the_first_example_variable' =&gt; get_option('siteurl'),
			'the_second_example_variable' =&gt; 'Oh no, my admin theme panel is working!!! COOL!!!',
			'the_get_querystring' =&gt; $this-&gt;input-&gt;get('page')
		), TRUE);
	}
}
</pre>
<h4>other_theme_controller.php</h4>
<pre class="brush: plain;">
&lt;?php

class Another_theme_controller extends Controller
{

	function Another_theme_controller()
	{
		parent::Controller();
	}

	function index()
	{
		echo $this-&gt;load-&gt;view('my_another_view', array(), TRUE);
	}
}
</pre>
<h3>Step 6</h3>
<p>Now you need to create two view files</p>
<h4>my_view.php</h4>
<pre class="brush: plain;">
&lt;h3&gt;&lt;?php echo $the_second_example_variable; ?&gt;&lt;/h3&gt;
This is my site url : &lt;?php echo $the_first_example_variable; ?&gt;
&lt;br/&gt;
This is the get querystring : &lt;?php echo $the_get_querystring; ?&gt;
</pre>
<h4>my_another_view.php</h4>
<pre class="brush: plain;">
&lt;h3&gt;This is my another view&lt;/h3&gt;
</pre>
<p>If you click on your new menu panel, you will see that your controller and view are loaded.</p>
<p><a href="http://www.feelinc.me/wp-content/uploads/2010/03/theme-panel.jpg"><img class="aligncenter size-medium wp-image-260" title="theme-panel" src="http://www.feelinc.me/wp-content/uploads/2010/03/theme-panel-300x142.jpg" alt="" width="300" height="142" /></a></p>
<h3>Conclusion</h3>
<p>We have now integrate CodeIgniter into your WordPress Options Panel.</p>
<p>Click below link to download the source.</p>
<a class="downloadlink" href="http://www.feelinc.me/wp-content/plugins/download-monitor/download.php?id=2" title="Version1.0 downloaded 153 times" >WordPress - CodeIgniter Options Panel (153)</a>
<p>I hope this tutorial gave you all the information you need to integrate CodeIgniter into your WordPress Options Panel. Please feel free to post your comments below.</p>
<p>Thanks for reading! ^_^</p>
]]></content:encoded>
			<wfw:commentRss>http://www.feelinc.me/experience/create-a-wordpress-options-panel-using-codeigniter/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
