<?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>Es Tea Double Eye &#187; kohanaphp</title>
	<atom:link href="http://stii.co.za/tag/kohanaphp/feed/" rel="self" type="application/rss+xml" />
	<link>http://stii.co.za</link>
	<description>You&#039;re never too old for a happy childhood</description>
	<lastBuildDate>Fri, 19 Aug 2011 02:20:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<atom:link rel='hub' href='http://stii.co.za/?pushpress=hub'/>
		<item>
		<title>Back to Code Igniter.</title>
		<link>http://stii.co.za/php/back-to-code-igniter/</link>
		<comments>http://stii.co.za/php/back-to-code-igniter/#comments</comments>
		<pubDate>Tue, 05 Oct 2010 18:16:26 +0000</pubDate>
		<dc:creator>Stii</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[kohanaphp]]></category>
		<category><![CDATA[mvc]]></category>

		<guid isPermaLink="false">http://stii.co.za/?p=1317</guid>
		<description><![CDATA[I&#8217;ve been developing with Code Igniter for years. One thing that irritated me endlessly is the fact that they destroy the $_GET variable since it does not utilize GET strings, there is no reason to allow it. Never mind that we as developers might want to use it. :P There is a way to access [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://stii.co.za/php/back-to-code-igniter/attachment/cikohana/" rel="attachment wp-att-1318"><img src="http://stii.co.za/wp-content/uploads/2010/10/cikohana.png" alt="" title="Code Igniter and KohanaPHP" width="565" height="78" class="aligncenter size-full wp-image-1318" /></a></p>
<p>I&#8217;ve been developing with <a href="http://codeigniter.com">Code Igniter</a> for years. One thing that irritated me endlessly is the fact that they destroy the <strong>$_GET variable</strong> since it does not utilize GET strings, there is no reason to allow it. Never mind that we as developers might want to use it. :P There is a way to <a href="http://biostall.com/enable-get-variables-when-using-codeigniter">access GET variables in Code Igniter</a>, but that mean you have to secure it yourself as it doesn&#8217;t get parsed by the system&#8217;s filters. It is an annoyance. It was a big enough annoyance for me to ditch Code Igniter for <a href="http://kohanaframework.org/">KohanaPHP</a>, which was based on Code Igniter. </p>
<p>KohanaPHP was brilliant. It was everything Code Igniter was and more. It even supported GET strings and was pure OOP. A thing of beauty. </p>
<p>It is a pity that they decided to change it all and redevelop the entire system. Besides that it is now a completely new or different system, the documentation is horrible and I downloaded and installed the latest version and it seems to be incomplete. Trying to set up the database, I found the database config file is missing. The documentation says &#8220;An example config file can be found at modules/database/config/database.php.&#8221; which sadly is not true. </p>
<p>I have no doubt the new KohanaPHP will rock once completed, but I am far, far, FAR to busy to get a new system working. The old KohanaPHP was perfect for me. Sadly, in future it will be no more. That left me with the only other option. Back to Code Igniter. GET madness and all. I will check it out when things calm down and I have a gap to learn the new KohanaPHP, but that won&#8217;t be anytime soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://stii.co.za/php/back-to-code-igniter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>KohanaPHP and Memcached</title>
		<link>http://stii.co.za/php/kohanaphp-and-memcached/</link>
		<comments>http://stii.co.za/php/kohanaphp-and-memcached/#comments</comments>
		<pubDate>Mon, 25 May 2009 13:56:33 +0000</pubDate>
		<dc:creator>Stii</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[kohanaphp]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://stii.co.za/?p=675</guid>
		<description><![CDATA[This is shockingly simple&#8230; Almost so simple that I&#8217;m waiting for the problems, but after five days there has been none so far! When you develop a web application, at some point SQL query optimization just don&#8217;t cut it anymore. At Gatorpeeps, you will see we show each user&#8217;s latest blog post underneath each of [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://stii.co.za/wp-content/uploads/2009/01/picture-24.png" alt="Kohana PHP" title="Kohana PHP" width="358" height="142" class="alignright size-full wp-image-172" />This is shockingly simple&#8230; Almost so simple that I&#8217;m waiting for the problems, but after five days there has been none so far!</p>
<p>When you develop a web application, at some point SQL query optimization just don&#8217;t cut it anymore. At <a href="http://gatorpeeps.com">Gatorpeeps</a>, you will see we show each user&#8217;s latest blog post underneath each of his updates. The problem with this is that on any given page, we&#8217;ll run a query per update to get the user&#8217;s latest blog post. This is less than ideal, since it is repeating the same queries for every single visitor to a <strong>Gatorpeeps</strong> page.</p>
<p>What we want to do is to cache the repetitive query for a certain amount of time, so that instead of querying the database, it fetches it from the cache, dramatically <strong>reducing database load</strong> and improving speed.</p>
<p>With the <a href="http://stii.co.za/tag/kohanaphp">Kohana PHP framework</a> you have a number of options to your disposal namely:</p>
<ul>
<li>File &#8211; File cache is fast and reliable, but requires many filesystem lookups.</li>
<li>SQlite &#8211; Database cache can be used to cache items remotely, but is slower.</li>
<li>Memcache &#8211; Memcache is very high performance, but prevents cache tags from being used.</li>
<li>APC &#8211; Alternative Php Cache</li>
<li>Eaccelerator</li>
<li>Xcache</li>
</ul>
<p>We opted for <a href="http://www.danga.com/memcached/">Memcached</a> since it is fast, stable (so far at least!) and extremely simple to get going. We installed and configured it on our server (you should find lots of great guides for doing this if you search for it). We made sure the daemon is running then configured Kohana to use it. Very simple:</p>
<p>Open the <strong>cache.php</strong> file located in the <strong>system/config</strong> directory. Change it to:</p>
<pre>
$config['default'] = array
(
	'driver'   => 'memcache',
	'params'   => '',
	'lifetime' => 3600,
	'requests' => 1000
);
</pre>
<p>If you run <strong>Memcached</strong> on the same server as your PHP site, you can skip ahead and implement it. If you run it on a different server, you need to change the <strong>cache_memcache.php</strong> file also located in <strong>system/config</strong>. If you have more than one memcached server, you can add them to the $config['servers'] array.</p>
<pre>
$config['servers'] = array
(
	array
	(
		'host' => '127.0.0.1',
		'port' => 11211,
		'persistent' => FALSE,
	)
);

/**
 * Enable cache data compression.
 */
$config['compression'] = FALSE;
</pre>
<p>In your source code, you can now use the cache. We have a static function in a helper method to fetch the latest blog post of a user. We get a cache instance and we check if the entry exists in the cache. If it does, we return the result otherwise we add it to the cache with a lifetime of 10 minutes.</p>
<pre>
&lt;?php
... truncated ...
public static function getUserLatestBlogPost($user_id)
{
    $cache = Cache::instance();

    // Get the latest blog post from the cache by looking for an unique id like latest_post_123
    $post = $cache->get('latest_post_' . $user_id);
    if ($post) {
        // Found an entry in the cache. Return it.
        return $post;
    } else {
        // There is nothing in the cache for this user, so we need to fetch it from the database and
        // add it to the cache.
        $newpost = self::sqlUserLatestBlogPost($user_id);

        // Add it to the cache, changing the default lifetime from 1 hour (3600 seconds) to 10 minutes (600 seconds)
        $cache->set('latest_post_' . $user_id, $newpost, NULL, 600);
        return $newpost;
    }
}
... truncated ...
</pre>
<p>That&#8217;s it. It is really that simple! :) Now, you would probably want to write a method that deletes an old entry if a new entry is inserted into the database and reload the new blog post into the cache.</p>
<p><strong><em>REMEMBER</em></strong>: Use caching wisely! It is great, but as they say, too much of a good thing is bad. First make sure your SQL queries are properly optimized before you cache it. Make sure the data you cache is okay to be cached. What I mean by that is it would be senseless to cache data that is very dynamic and changes often. Caching everything WILL have an undesirable effect ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://stii.co.za/php/kohanaphp-and-memcached/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>More reasons for Gatorpeeps</title>
		<link>http://stii.co.za/afrigator/more-reasons-for-gatorpeeps/</link>
		<comments>http://stii.co.za/afrigator/more-reasons-for-gatorpeeps/#comments</comments>
		<pubDate>Mon, 11 May 2009 11:54:12 +0000</pubDate>
		<dc:creator>Stii</dc:creator>
				<category><![CDATA[Afrigator]]></category>
		<category><![CDATA[gatorpeeps]]></category>
		<category><![CDATA[kohanaphp]]></category>
		<category><![CDATA[microblogging]]></category>

		<guid isPermaLink="false">http://stii.co.za/?p=633</guid>
		<description><![CDATA[Finally we can talk about Gatorpeeps officially! We&#8217;ve been rather quiet about it, primarily since we needed to finish a few things and stress test it before we punted it. We had our fair share of &#8220;Blegh, another Twitter clone&#8230;&#8221; and we expected it. The thing is, we love twitter! Always have, always will. So [...]]]></description>
			<content:encoded><![CDATA[<p>Finally we can talk about <a href="http://gatorpeeps.com">Gatorpeeps</a> officially! We&#8217;ve been rather quiet about it, primarily since we needed to finish a few things and stress test it before we punted it.</p>
<p><a href="http://gatorpeeps.com"><img src="http://stii.co.za/wp-content/uploads/2009/05/gatorpeeps.png" alt="gatorpeeps" title="gatorpeeps" width="303" height="120" class="aligncenter size-full wp-image-634" /></a></p>
<p>We had our fair share of &#8220;Blegh, another <a href="http://stii.co.za/tag/twitter/">Twitter</a> clone&#8230;&#8221; and we expected it. The thing is, we love twitter! Always have, always will. </p>
<p>So why did we clone it then? Simple. Some of the reasons<a href="http://justinhartman.com/2009/05/11/afrigator-tried-to-buy-twitter-we-launched-gatorpeeps-instead/"> Justin already covered over here</a>, but I&#8217;d like to add that <a href="http://afrigator.com">Afrigator</a> was in need of something <strong>social networky</strong>. We needed to add a <strong>communication dimension</strong> and as everybody knows, there is no better way to do that other than <strong>Twitter</strong>. Yes, we could have leveraged off the Twitter API. That is true, but the Twitter API is not without it&#8217;s limitations.</p>
<p>Besides that, we also have a few other ideas, such as Twitter recently killed <strong>SMS</strong> functionality in <a href="http://afrigator.com">Africa</a>, and it left a huge gaping gap in that market. </p>
<p>We did not leverage off some <a href="http://stii.co.za/tag/opensource/">Open Source</a> app like <a href="http://laconi.ca" rel="nofollow">Laconi.ca</a> or <a href="http://jaiku.com" rel="nofollow">Jaiku</a>. We wanted to initially, but due to the fact that we want to seamlessly integrate <strong>Gatorpeeps</strong> with <strong>Afrigator</strong> and add a bunch of unique features, we thought it best to rather develop our own flavor into the mix. For those interested, it is backed up by the brilliant <a href="http://stii.co.za/tag/kohanaphp/">Kohana PHP</a> framework :). Was it the best idea? The right thing to do? Time will tell. </p>
<p>Now the real work starts. Now we need to do all these promised features and integration&#8230; Fun times!  </p>
]]></content:encoded>
			<wfw:commentRss>http://stii.co.za/afrigator/more-reasons-for-gatorpeeps/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Kohana PHP. One application, many domains?</title>
		<link>http://stii.co.za/php/kohana-php-one-application-many-domains/</link>
		<comments>http://stii.co.za/php/kohana-php-one-application-many-domains/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 11:55:39 +0000</pubDate>
		<dc:creator>Stii</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[kohanaphp]]></category>

		<guid isPermaLink="false">http://stii.co.za/?p=184</guid>
		<description><![CDATA[In Kohana PHP&#8216;s config file they have a bunch of weird settings that you have to specify. I cannot for the life of Brian understand why! :P I&#8217;m talking about this. The very first thing you need to set: &#60;?php $config['site_domain'] = 'mysite.com'; Now, I can understand the logic if you want to run your [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://stii.co.za/php/kohana-php-framework/">Kohana PHP</a>&#8216;s <strong>config file</strong> they have a bunch of weird settings that you have to specify. I cannot for the life of Brian understand why! :P</p>
<p>I&#8217;m talking about this. The very first thing you need to set:</p>
<pre>
&lt;?php

$config['site_domain'] = 'mysite.com';
</pre>
<p>Now, I can understand the logic if you want to run your site off a directory in your domain like mysite.com/mysite, but still. Personally, I think, the URL should not be forced and it should rather just use <strong>$_SERVER['SERVER_NAME']</strong> to determine the site domain. What they should ask is for a directory config item if you want to run your site off a directory on your domain:</p>
<pre>
&lt;?php
//Leave blank if site is in the root directory
$config['site_directory'] = 'mysite';
</pre>
<p>Now lets suppose you want to do a mobile site. You should never have to replicate your code and maintain 2 code bases. You know. The <acronym title="Don't Repeat Yourself">DRY</acronym> principles? I want to run two domains off the same code base, but make my decision in the code whether I want to display default site templates or whether I must display the mobile templates. (See: <a href="http://stii.co.za/php/overriding-default-template-in-kohana-php/">Overriding default template in Kohana PHP</a> if you&#8217;re unsure what I&#8217;m on about). For example: I have my normal site running on http://mysite.com and I want my mobile site to live at http://mysite.mobi. The difference between the two are the templates. I want to use the rest of the codebase as is since they&#8217;re all the same for both sites.</p>
<p>The solution is pretty much straight forward. All you need to do is:</p>
<pre>
&lt;?php

$config['site_domain'] = $_SERVER['SERVER_NAME'];
</pre>
<p>or (if your application lives in a directory)</p>
<pre>
&lt;?php

$config['site_domain'] = $_SERVER['SERVER_NAME'] . '/mysite';
</pre>
<p>and viola! It works like a charm. <strong>But it is still very unnecessary!</strong> That&#8217;s my beef about it. This is one of those weird things that spilled over from <a href="http://codeigniter.com" rel="nofollow">Code Igniter</a>. Maybe this could change at some stage? Maybe I&#8217;m missing something and in fact it is quite critical that you do specify it like they prefer? Hope someone could clarify. It is quite possible that I&#8217;m missing something very obvious&#8230; I&#8217;m known for that from time to time!</p>
<h2>UPDATE&#8230; Sigh</h2>
<p>It turns out that if you leave $config['site_domain'] blank, it defaults to using $_SERVER['SERVER_NAME']. </p>
<pre>
&lt;?php

$config['site_domain'] = '';
</pre>
<p>At least, now I know! </p>
<p>Also, read <a href="http://whijo.net/">Darb</a>&#8216;s comment below on why you&#8217;d want to enforce a single domain. Makes sense!</p>
]]></content:encoded>
			<wfw:commentRss>http://stii.co.za/php/kohana-php-one-application-many-domains/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Overriding default template in Kohana PHP</title>
		<link>http://stii.co.za/php/overriding-default-template-in-kohana-php/</link>
		<comments>http://stii.co.za/php/overriding-default-template-in-kohana-php/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 14:57:34 +0000</pubDate>
		<dc:creator>Stii</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[kohanaphp]]></category>
		<category><![CDATA[template_controller]]></category>

		<guid isPermaLink="false">http://stii.co.za/?p=175</guid>
		<description><![CDATA[If you use the template controller in Kohana PHP you may need to override the default template you specified at some stage. This is extremely easy, but it is not documented anywhere, so I thought it might be a good idea to show you. Normally you would specify the default template like this: &#60;?php class [...]]]></description>
			<content:encoded><![CDATA[<p>If you use the <strong>template controller</strong> in <a href="http://stii.co.za/php/kohana-php-framework/">Kohana PHP</a> you may need to override the default template you specified at some stage. This is extremely easy, but it is not documented anywhere, so I thought it might be a good idea to show you.</p>
<p>Normally you would specify the default template like this:</p>
<pre>
&lt;?php
class Home_Controller extends Template_Controller
{
    public $template = 'my_template';
    ...
}
</pre>
<p>Now lets suppose you are developing a mobile version of your site and you would like to use a different template for whatever reason. In your index() function you would have something like this:</p>
<pre>
&lt;?php
class Home_Controller extends Template_Controller
{
    public $template = 'my_template';
    ...
    public function index()
    {
        if ($is_mobile) {
            //Use a different mobile template
            $this->template = new View("mobile_template");
            ...
        } else {
            //Do the normal thing and let it
            //auto generate the page and use my_template
            ...
        }
    }
}
</pre>
<p>In effect, all you need to do is to override your default specified &#8220;my_template&#8221; by assigning a new View object which would be a different template that does what you need it to do.</p>
<p>Another way of doing it is as follows:</p>
<pre>
&lt;?php
class Home_Controller extends Template_Controller
{
    public $template = 'my_template';

    public function __construct()
    {
        if ($is_mobile) {
            $this->template = 'mobile_template';
        }
        parent::__construct();
    }
...
}
</pre>
<p>Assign your new template to the variable in your controller&#8217;s constructor before you call the parent class (<strong>Template_Controller</strong>) constructor. The <strong>Template_Controller</strong> does the following in it&#8217;s constructor, FYI:</p>
<pre>
$this->template = new View($this->template);
</pre>
<p>If you do the following, it would #FAIL:</p>
<pre>
&lt;?php
class Home_Controller extends Template_Controller
{
    public $template = 'my_template';

    public function __construct()
    {
        parent::__construct();
        if ($is_mobile) {
            $this->template = 'mobile_template';
        }
    }
...
}
</pre>
<p>If its not obvious to you, what happens is that in the <strong>Template_Controller</strong> constructor it assigns the my_template View object to the $this->template variable and if you assign &#8216;mobile_template&#8217; to it after the <strong>Template_Controller</strong> constructor was called, you effectively override $this->template with a string called &#8216;mobile_template&#8217;. Very effectively&#8230; ;-)</p>
<p>There! I hope this helps someone somewhere.</p>
]]></content:encoded>
			<wfw:commentRss>http://stii.co.za/php/overriding-default-template-in-kohana-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Kohana PHP Framework</title>
		<link>http://stii.co.za/php/kohana-php-framework/</link>
		<comments>http://stii.co.za/php/kohana-php-framework/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 14:09:29 +0000</pubDate>
		<dc:creator>Stii</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[kohanaphp]]></category>
		<category><![CDATA[mvc]]></category>

		<guid isPermaLink="false">http://stii.co.za/?p=170</guid>
		<description><![CDATA[Now I&#8217;m not going to start a &#8220;my-framework-is-better-than-yours&#8221; pissing contest again. I&#8217;ve learned that 1) People are not easily convinced that what they are using is actually inferior to what they should be using and 2) life is simply too short to try and convince people otherwise. No, I will say that Kohana PHP is [...]]]></description>
			<content:encoded><![CDATA[<p>Now I&#8217;m not going to start a &#8220;<em>my-framework-is-better-than-yours</em>&#8221; pissing contest again. I&#8217;ve learned that 1) People are not easily convinced that what they are using is actually inferior to what they should be using and 2) life is simply too short to try and convince people otherwise.</p>
<p><a href="http://kohanaphp.com/"><img src="http://stii.co.za/wp-content/uploads/2009/01/picture-24.png" alt="picture-24" title="picture-24" width="358" height="142" class="aligncenter size-full wp-image-172" /></a></p>
<p>No, I will say that <a href="http://kohanaphp.com/">Kohana PHP</a> is <strong><em>MY</em></strong> framework of choice. I like the way it utilize strict <strong>PHP5</strong> <acronym title="Object Orientated Programming">OOP</acronym> practices. It is very similar to <a href="http://codeigniter.com/">Code Igniter</a> and I&#8217;ve been a fan of <strong><acronym title="Code Igniter">CI</acronym></strong> for a long, long time. In fact, it was based on <strong><acronym title="Code Igniter">CI</acronym></strong>. I like the flexibility. I like the way templates and views work. I like the way it uses convention over configuration or as they call it &#8220;<em>a cascading filesystem</em>&#8220;. I like the fact that it allows you to access the <strong>$_GET</strong> variables which <strong><acronym title="Code Igniter">CI</acronym></strong> does not by default. I can go on and on and on. There are many. The list is too bloody long. </p>
<p>The community is smallish, but it is growing. It is completely <strong>Open Source</strong> and is not controlled or maintained by a single entity as is the case with <strong><acronym title="Code Igniter">CI</acronym></strong>. </p>
<p>All in all, it fits me. It allows me to do what I need to do quickly. I know it might not be perfect, but that does not matter as long as it gets my work done.   </p>
<p>Word of advice: If you are looking for a neat/fast/flexible little framework in <strong>PHP</strong>, check it out. I highly recommend it! :)</p>
<p>Oh, and <acronym title="For Your Information">FYI</acronym>, both <a href="http://stii.co.za/tag/afrigator/">Afrigator</a> and (I believe) <a href="http://ushahidi.com/">Ushahidi</a> are proudly <strong>Kohana PHP Powered</strong>!</p>
]]></content:encoded>
			<wfw:commentRss>http://stii.co.za/php/kohana-php-framework/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

