<?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>Query7 &#187; Code Igniter</title>
	<atom:link href="http://query7.com/category/code-igniter/feed" rel="self" type="application/rss+xml" />
	<link>http://query7.com</link>
	<description>PHP, Javascript, Python and Web Development</description>
	<lastBuildDate>Sat, 25 Jun 2011 21:29:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Internationalization and Partial Rendering in the CodeIgniter Framework</title>
		<link>http://query7.com/internationalization-and-partial-rendering-in-the-codeigniter-framework</link>
		<comments>http://query7.com/internationalization-and-partial-rendering-in-the-codeigniter-framework#comments</comments>
		<pubDate>Mon, 06 Sep 2010 16:59:10 +0000</pubDate>
		<dc:creator>Prakash Mohanty</dc:creator>
				<category><![CDATA[Code Igniter]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[localization]]></category>
		<category><![CDATA[multi-language]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.webdevelopmentbits.com/?p=678</guid>
		<description><![CDATA[As experienced Web developers, it won’t shock you to find literally thousands of comparisons between CodeIgniter and the other popular frameworks you may be considering for your site. Each framework has its good and, ummm… less good points, but]]></description>
			<content:encoded><![CDATA[<p>As experienced Web developers, it won’t shock you to find literally thousands of comparisons between <a href="http://codeigniter.com/">CodeIgniter</a> and the other popular frameworks you may be considering for your site. Each framework has its good and, ummm… <em>less good </em>points, but let’s say you’re wedded to CodeIgniter for whatever reason, and you’ve got a few languages you’re tasked with supporting so you’re getting set to work on internationalization. So you go back and refresh your memory of just how to do that, and you begin coming across certain sites saying that CodeIgniter doesn&#8217;t support internationalization. So you begin to ponder ditching CodeIgniter, since you’re aces in a couple other frameworks, but that would be a mistake. CodeIgniter is a genius framework, and well optimized for so many other tasks that it’s worth sticking with. Plus, we have a nifty solution to your CodeIgniter internationalization issues.</p>
<p>If you’re going to be developing a multi-language site, then when you’re setting up your CMS, from the beginning be sure to go for a CodeIgniter CMS like CI-CMS or Pyro CMS in order to minimize languages issues down the road. {The <a href="http://www.zend.com/en/">Zend</a> framework, with its strong partial rendering, may seem like a better option in a pinch, but CodeIgniter trumps Zend in other crucial areas, so it’s worth sticking with.}</p>
<p>With CodeIgniter it makes great sense to build in modular separation (you can find the library <a href="http://maestric.com/doc/php/codeigniter_i18n">here</a>), though at first glace I’ll agree it looks like a tough implementation.</p>
<p>As you scan the library article, the lines to put most emphasis on will naturally deal with switching languages.</p>
<p>For example, you’ll find in the Notes section of the above library site:</p>
<pre>&lt;?php

anchor($this-&gt;lang-&gt;switch_uri('fr'),'Display current page in French');
$lang['about.gender'] = "Je suis un homme";

?&gt;</pre>
<p>Plug the lines below into your route.php and config.php files.</p>
<p>In config/route.php :</p>
<pre>&lt;?php

$route['^fr/(.+)$'] = "$1";

$route['^en/(.+)$'] = "$1";

// '/en' and '/fr' URIs -&gt; use default controller

$route['^fr$'] = $route['default_controller'];

$route['^en$'] = $route['default_controller'];

?&gt;</pre>
<p>In config/config.php,</p>
<p>$config['base_url']  must correspond to your configuration. For example,</p>
<pre>&lt;?php

$config['index_page'] = "";

?&gt;</pre>
<p>Creating the language file in system/application/language/english/about_lang.php was already clear to you.</p>
<pre>&lt;?php

$lang['about.gender'] = "I'm a man";
$lang['about.gender'] = "Je suis un homme";

?&gt;</pre>
<p>The controller part at</p>
<p>system/application/controllers/about.php should also be clear to you.</p>
<p>In the index function</p>
<pre>&lt;?php

$this-&gt;load-&gt;helper('language');

$this-&gt;load-&gt;helper('url');

// load language file‚

$this-&gt;lang-&gt;load('about');

$this-&gt;load-&gt;view('about');

?&gt;</pre>
<p>Once you&#8217;re done with these, browse to the welcome module on your local machine at http://localhost/ci/fr/welcome/test.<br />
You should find the language lines show up as expected.</p>
<p>Be sure to hit the CodeIgniter <a href="http://codeigniter.com/wiki/Language_Translation/">resource site</a> for some really useful, ready made down loadable translation files in zip format. This’ll save you heaps of time and work. Once you’ve extracted these zip archives, you’ll find files named as in the <em>about_lang.php </em>as above.</p>
<p>Next, while looking into partial rendering, we come across <a href="http://codeigniter.com/wiki/View_Object_PHP5/">this site</a>, which brings us more clarity.</p>
<pre>&lt;?php

$this-&gt;view-&gt;layout = 'master_layout_file'; // or leave this empty to render partials only

//Add a partial file and (optional) $data‚

$header = $this-&gt;view-&gt;load('header','header_file',$data);

// subheader‚

$header-&gt;load('sub_header','sub_header_file',$data);

$header-&gt;set($data);

$this-&gt;view-&gt;render();

?&gt;</pre>
<p>Now let’s render the partials in our master template:</p>
<pre>&lt;?php $header-&gt;render();?&gt;;</pre>
<p>And that&#8217;s about it. Pretty simple, right?</p>
<p>Before closing, just a brief note: PyroCMS is a multilingual CodeIgniter CMS with built-in language configuration options you can tailor to your site. You can find language settings inside the admin panel, and while the implementation will be similar to the approach we’ve outlined above it may not be an exact match.</p>
<p>Well, that&#8217;s it!  Thanks for reading, and I hope this helps.  If you have any questions about this specific tutorial or any other issues re: web development with CodeIgniter, Zend, or whatever else, drop us a line any time from our contact page!</p>
<p>Prakash R. Mohanty</p>
<p>Senior Software Engineer<br />
Sourcebits Technologies</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/internationalization-and-partial-rendering-in-the-codeigniter-framework/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a Todo List using Code Igniter</title>
		<link>http://query7.com/building-a-todo-list-using-code-igniter</link>
		<comments>http://query7.com/building-a-todo-list-using-code-igniter#comments</comments>
		<pubDate>Sat, 18 Apr 2009 02:06:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Igniter]]></category>

		<guid isPermaLink="false">http://query7.com/?p=422</guid>
		<description><![CDATA[<p>A Query7 reader <a href="http://query7.com/getting-started-with-code-igniter/#comments">requested</a> this tutorial to be written. It&#8217;s aimed to be a general guide to build &#8216;something&#8217; using Code Igniter. It uses Models, Views, Controllers, Helpers and Libraries and will give you a good idea how Code Igniter works as a whole. I will be posting more advanced Code Igniter tutorials in the future.</p>
<h2>Setup</h2>
<p>Install and do some basic configuration (URL, database settings) of Code Igniter. If you don&#8217;t know how to do this, read <a href="http://query7.com/getting-started-with-code-igniter/">here</a>. Autoload the <em>database</em> library and <em>url</em> helper as we will be using them.</p>
<p>The user will be able to post new items and delete current items and the app itself will be made up of:</p>
<ul>
<li>One Controller &#8211; todo.php</li>
<li>One Model &#8211; todo_model.php</li>
<li>One View &#8211; todo_index.php</li>
</ul>
<h2>PHP4 Compatibility</h2>
<p>Because Code Igniter supports both PHP4 and PHP5, you are forced to use PHP4 style OOP. Your constructor must be the same name as the class, and it needs to contain <em>parent::Controller();</em> or <em> parent::Model();</em><br />
The naming conventions for controllers and models are very strict. The name of both class and constructor must be the same as the file name, but capitalized. In our case of our controller,&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>A Query7 reader <a href="http://query7.com/getting-started-with-code-igniter/#comments">requested</a> this tutorial to be written. It&#8217;s aimed to be a general guide to build &#8216;something&#8217; using Code Igniter. It uses Models, Views, Controllers, Helpers and Libraries and will give you a good idea how Code Igniter works as a whole. I will be posting more advanced Code Igniter tutorials in the future.</p>
<h2>Setup</h2>
<p>Install and do some basic configuration (URL, database settings) of Code Igniter. If you don&#8217;t know how to do this, read <a href="http://query7.com/getting-started-with-code-igniter/">here</a>. Autoload the <em>database</em> library and <em>url</em> helper as we will be using them.</p>
<p>The user will be able to post new items and delete current items and the app itself will be made up of:</p>
<ul>
<li>One Controller &#8211; todo.php</li>
<li>One Model &#8211; todo_model.php</li>
<li>One View &#8211; todo_index.php</li>
</ul>
<h2>PHP4 Compatibility</h2>
<p>Because Code Igniter supports both PHP4 and PHP5, you are forced to use PHP4 style OOP. Your constructor must be the same name as the class, and it needs to contain <em>parent::Controller();</em> or <em> parent::Model();</em><br />
The naming conventions for controllers and models are very strict. The name of both class and constructor must be the same as the file name, but capitalized. In our case of our controller, the file name is <em>todo.php</em> and the name of the class and constructor is called <em>Todo</em>.</p>
<h2>Model</h2>
<p>The model in Code Igniter is a place where you write your application&#8217;s SQL queries (It doesn&#8217;t map your schema like in Django/RoR). In our application we specify 3 methods, which can then be called upon in the controller. You will notice we are using the Code Igniter database class but not Code Igniter&#8217;s full ORM. This is just personal preference. In get_all_todo_items() we call <em>$q-&gt;result_array()</em> . Think of it as an equivalent to<em> mysql_fetch_array()</em>.</p>
<pre lang="php">class Todo_model extends Model {

    function Todo_model()

    {

        parent::Model();

    }

	function new_todo($content)

	{
		$date = date('l jS \of F Y h:i:s A');

		$q = $this-&gt;db-&gt;query("INSERT INTO items (date,content) VALUES ('$date','$content')");

	}

	function get_all_todo_items()
	{
		$q = $this-&gt;db-&gt;query("SELECT id,date,content FROM items");
		return $q-&gt;result_array();
	}

	function delete_todo_item($id)
	{
		$q = $this-&gt;db-&gt;query("DELETE FROM items WHERE id = '$id'");
	}

}</pre>
<h2>Controller</h2>
<blockquote><p>/system/application/controllers/todo.php</p></blockquote>
<p>You can also see in the Controller that we are loading the <em>form</em> helper and <em>todo_model</em> model. Notice there are no file extensions being used. In Code Igniter URLs are structured like: <em>www.foo.com/ci/index.php/controller/method/</em>. If no method is specified then Code Igniter will automatically run the <em>index()</em> method.</p>
<p><strong>index_page()</strong><br />
We assign the results of <em>get_all_todo_items()</em> to <em>$info['item']</em> . We then pass the $info array (which contains all of our todo items) to our view which we&#8217;ll create soon.<br />
<strong>add_item()</strong><br />
Rather than using <em>$_POST['content']</em> to access a property, you should use <em>$this-&gt;input-&gt;post(&#8216;content&#8217;)</em>. This utilises Code Igniter&#8217;s input class which automatically filters out SQL injections and XSS attacks (<em>line 266 /application/config/config.php</em>)<br />
We then pass the result from that to our new_todo() method in our model and redirect the user back to the index page.<br />
<strong>delete_item()</strong><br />
We can use the <em>segment()</em> method in the <em>uri</em> class to grab bits of information from the URL. Because our URI will be <em>/todo/delete_item/id/</em>, by grabbing the 3rd segment we get the id. We can then feed that do our <em>delete_todo_item()</em> method we defined in the model and redirect the user to the main page.</p>
<pre lang="php">class Todo extends Controller {

	function Todo()
	{
		parent::Controller();
                $this-&gt;load-&gt;helper('url');
		$this-&gt;load-&gt;helper('form');
		$this-&gt;load-&gt;model('todo_model');
	}

	function index()
	{
		$this-&gt;index_page();
	}

	function index_page()
	{
		$info['item'] = $this-&gt;todo_model-&gt;get_all_todo_items();
		$this-&gt;load-&gt;view('todo_index.php', $info);
	}

	function add_item()
	{
		$content = $this-&gt;input-&gt;post('content');
		$this-&gt;todo_model-&gt;new_todo($content);

		redirect('');
	}

	function delete_item()
	{
		$this-&gt;todo_model-&gt;delete_todo_item($this-&gt;uri-&gt;segment(3));

		redirect('');
	}
}</pre>
<p>Finally we need to write our view.</p>
<blockquote><p>/system/application/views/todo_index.php</p></blockquote>
<p>On line 5 you can see the form_open() function being used. This creates our opening form tag. The <em>action</em> attribute is specified by the parameter that we passed. Code Igniter automatically prepends your site URL to this parameter it ends up as <em>action=&#8221;http://path_to_site.com/URI_passed&#8221;</em>. This is useful because if we move the site to another domain name, the form will continue to post to the correct URL. Between lines 12 and 17 we are iterating through the todo items posted.</p>
<pre>&lt;h1&gt;Todo List&lt;/h1&gt;

&lt;hr /&gt;

&lt;?php echo form_open('todo/add_item'); ?&gt;

	&lt;textarea cols="40" rows="10" name="content"&gt;&lt;/textarea&gt;
	&lt;input type="submit" value="Add new item" /&gt;
&lt;/form&gt;

&lt;ul&gt;
&lt;?php
for($i = 0; $i &lt; sizeof($item); ++$i)
{
    echo '&lt;li&gt;' . $item[$i]['content'] . ' - &lt;i&gt;' . $item[$i]['date'] . '&lt;/i&gt; - &lt;a href="' . site_url() . '/todo/delete_item/' . $item[$i]['id'] . '"&gt;Delete&lt;/a&gt;&lt;/li&gt;';
}
?&gt;
&lt;/ul&gt;

&lt;hr /&gt;
&lt;p&gt;Created by &lt;a href="http://www.query7.com"&gt;Query7&lt;/a&gt;&lt;/p&gt;</pre>
<p>Feel free to post any questions or comments you have.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/building-a-todo-list-using-code-igniter/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting started with Code Igniter</title>
		<link>http://query7.com/getting-started-with-code-igniter</link>
		<comments>http://query7.com/getting-started-with-code-igniter#comments</comments>
		<pubDate>Sun, 29 Mar 2009 21:05:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Igniter]]></category>

		<guid isPermaLink="false">http://query7.com/?p=394</guid>
		<description><![CDATA[<h2>What is Code Igniter?</h2>
<p>Code Igniter is a PHP web framework which assists in creating complex websites. Unlike other web frameworks, Code Igniter doesn&#8217;t force you to use all of it&#8217;s components. You select and load them as you require. The only feature you have to use is the URL structuring (<em>/controller/method/</em>) which is very helpful anyway.</p>
<p>Code Igniter follows the Model, View, Controller (MVC) principle. All of your database queries are stored in models, HTML/XML output in Views and the logic code in Controllers. You aren&#8217;t forced to do this, however it does keep your code organized and reusable.</p>
<h2>Helpers and Libraries</h2>
<p>Like most frameworks, Code Igniter comes with many classes that help assist development. They are split into <em>Libraries</em> (AKA <em>Classes</em>) and <em>Helpers</em>. Libraries contain code that you could use on every page of your application &#8211; Database ORM, Image Manipulation, Pagination and Benchmarking. Helpers are things like Relative URLs, Forms and Email.</p>
<p>Using helpers and libraries is very easy. If you want it included throughout the site see below (autoloads). If you want it included for every method in a Controller, then you can add it to that Controller&#8217;s constructor. If you just want it included in&#8230;</p>]]></description>
			<content:encoded><![CDATA[<h2>What is Code Igniter?</h2>
<p>Code Igniter is a PHP web framework which assists in creating complex websites. Unlike other web frameworks, Code Igniter doesn&#8217;t force you to use all of it&#8217;s components. You select and load them as you require. The only feature you have to use is the URL structuring (<em>/controller/method/</em>) which is very helpful anyway.</p>
<p>Code Igniter follows the Model, View, Controller (MVC) principle. All of your database queries are stored in models, HTML/XML output in Views and the logic code in Controllers. You aren&#8217;t forced to do this, however it does keep your code organized and reusable.</p>
<h2>Helpers and Libraries</h2>
<p>Like most frameworks, Code Igniter comes with many classes that help assist development. They are split into <em>Libraries</em> (AKA <em>Classes</em>) and <em>Helpers</em>. Libraries contain code that you could use on every page of your application &#8211; Database ORM, Image Manipulation, Pagination and Benchmarking. Helpers are things like Relative URLs, Forms and Email.</p>
<p>Using helpers and libraries is very easy. If you want it included throughout the site see below (autoloads). If you want it included for every method in a Controller, then you can add it to that Controller&#8217;s constructor. If you just want it included in one method, add the code inside the method.</p>
<pre>$this-&gt;load-&gt;helper('helper_name');
$this-&gt;load-&gt;library('library_name');</pre>
<h2>Installation</h2>
<p>Installing Code Igniter is alot easier than installing other PHP web frameworks. There is no need for command line access, nor the need to write your database schema in XML. You only need to edit a few configuration files.</p>
<p>Download and Install the latest version off the Code Igniter <a href="http://codeigniter.com/downloads/">download page</a>. Extract it and upload it to your web server. You may notice the directory <em>/user_guide/</em> . This only contains documentation so it can be deleted safely. Up to date documentation can always be found at <a href="http://www.codeigniter.com/user_guide/">www.codeigniter.com/user_guide/</a>.</p>
<p>Now that Code Igniter has been &#8216;installed&#8217; we need to configure our settings. Open..</p>
<blockquote><p><em>/system/application/config/config.php</em></p></blockquote>
<p>On line 14 we need to set the path to our website. Make sure it has a trailing slash.</p>
<pre>$config['base_url']	= "http://www.website.com/path/to/codeigniter/";</pre>
<p>I also put global XSS filtering on. By default it is not active. Replace line 267 with..</p>
<pre>$config['global_xss_filtering'] = TRUE;</pre>
<p>If your application uses a database, now is a good time to set it up. Open..</p>
<blockquote><p><em>/system/application/config/database.php</em></p></blockquote>
<pre>$db['default']['hostname'] = "localhost"; //usually localhost
$db['default']['username'] = "usernamet";  //database username
$db['default']['password'] = "password";  //password to user set above
$db['default']['database'] = "database";  //database name
$db['default']['dbdriver'] = "mysql";  //database driver - mysql/postgre/sqlite etc..
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";</pre>
<p>When you call the database class, Code Igniter will connect to the database with the information you set in <em>$db['default']</em> array.</p>
<pre>$this-&gt;load-&gt;database();</pre>
<p>You can then interact with the database through</p>
<pre>$this-&gt;db-&gt;method();</pre>
<p>If your application uses more than one database, you can set another array in the same <em>database.php</em> file but call it a seperate name. eg <em>$db['remote']</em> (copy and paste the <em>$db['default']</em> array and change where necessary). You can then connect that database with..</p>
<pre>$remote_db = $this-&gt;load-&gt;database('remote', TRUE);</pre>
<p>And execute database methods through..</p>
<pre>$remote_db-&gt;method();</pre>
<p>I also recommend you set up autoloads..</p>
<blockquote><p><em>/system/application/config/autoload.php</em></p></blockquote>
<p>Here you can specify classes and helpers that will be available in every file throughout your project. This is useful because you won&#8217;t need to call them every time you make a new controller. I recommend <em>autoload</em>ing the database class and the URL helper. You will find the URL helper very useful in your Views, being able to use relative URLs instead of hard coding full <em>http://www.website.com/path/to/codeigniter/</em> URLs is very useful. You just need to add the name of the library/helper in the appropriate array..</p>
<pre>$autoload['libraries'] = array('database');
$autoload['helper'] = array('url');</pre>
<p>Thats it.. Feel free to ask any questions.<br />
In the next couple of weeks I&#8217;ll be writing a tutorial showing how to get a fully featured authentication system up and running with Code Igniter.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/getting-started-with-code-igniter/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

