<?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>visual77 &#187; kohana</title>
	<atom:link href="http://visual77.com/blog/tag/kohana/feed/" rel="self" type="application/rss+xml" />
	<link>http://visual77.com</link>
	<description>Ramblings from Steve Phillips</description>
	<lastBuildDate>Sat, 10 Sep 2011 21:19:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Kohana 2.x kotidy &#8211; Using the Tidy library to clean up Kohana&#8217;s HTML output</title>
		<link>http://visual77.com/blog/2010/09/kohana-2-x-kotidy-using-the-tidy-library-to-clean-up-kohanas-html-output/</link>
		<comments>http://visual77.com/blog/2010/09/kohana-2-x-kotidy-using-the-tidy-library-to-clean-up-kohanas-html-output/#comments</comments>
		<pubDate>Wed, 29 Sep 2010 19:11:17 +0000</pubDate>
		<dc:creator>visual77</dc:creator>
				<category><![CDATA[visual77]]></category>
		<category><![CDATA[ko23]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://visual77.com/blog/?p=643</guid>
		<description><![CDATA[In a quick followup to yesterday&#8217;s building and releasing autoasset, I&#8217;ve created another module to do something simple and portable for Kohana 2.x. This module, kotidy, uses the PHP Tidy library to clean up the HTML output immediately prior to display. Even though the HTML is not seen by the end user, I find myself [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><p>In a quick followup to <a href="http://visual77.com/blog/2010/09/kohana-2-x-autoasset-automatically-include-relevant-javascript-css-and-more/">yesterday&#8217;s building and releasing autoasset</a>, I&#8217;ve created another module to do something simple and portable for <a href="http://visual77.com/blog/tag/kohana">Kohana</a> 2.x. This module, kotidy, uses the <a href="http://php.net/tidy">PHP Tidy</a> library to clean up the HTML output immediately prior to display. Even though the HTML is not seen by the end user, I find myself OCD about this kind of stuff and want to know that my source code is clean, even if most people will never see it.</p>
<p>Just like autoasset, kotidy uses the Event system to hook a basic function in place to use the tidy library to clean up the output. Other than adding this module to your module list in the main config file, no work is required on your part, unless you want to customize the config data being sent to Tidy::parseString(), of course.</p>
<p><a href="http://visual77.com/blog/wp-content/uploads/2010/09/kotidy.zip">Download Kohana 2.x &#8211; kotidy</a></p>
<div class="shr-publisher-643"></div><!-- Start Shareaholic LikeButtonSetBottom --><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://visual77.com/blog/2010/09/kohana-2-x-kotidy-using-the-tidy-library-to-clean-up-kohanas-html-output/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kohana 2.x Autoasset &#8211; Automatically include relevant javascript, css and more</title>
		<link>http://visual77.com/blog/2010/09/kohana-2-x-autoasset-automatically-include-relevant-javascript-css-and-more/</link>
		<comments>http://visual77.com/blog/2010/09/kohana-2-x-autoasset-automatically-include-relevant-javascript-css-and-more/#comments</comments>
		<pubDate>Wed, 29 Sep 2010 06:00:25 +0000</pubDate>
		<dc:creator>visual77</dc:creator>
				<category><![CDATA[visual77]]></category>
		<category><![CDATA[ko23]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://visual77.com/blog/?p=638</guid>
		<description><![CDATA[I&#8217;ve set up about a half dozen Kohana 2.x sites now, and one problem that I constantly run into is including javascript / css based on the controller and method for the current page. For instance, if you go to &#8220;/user/view/1&#8243; on a Kohana site, I would like to automatically include &#8220;/javascript/user.js&#8221; or &#8220;/javascript/user/view.js&#8221;, if [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><p>I&#8217;ve set up about a half dozen <a href="http://visual77.com/blog/tags/kohana">Kohana</a> 2.x sites now, and one problem that I constantly run into is including javascript / css based on the controller and method for the current page. For instance, if you go to &#8220;/user/view/1&#8243; on a Kohana site, I would like to automatically include &#8220;/javascript/user.js&#8221; or &#8220;/javascript/user/view.js&#8221;, if the files exist.</p>
<p>To solve this problem, I created an autoasset module for Kohana 2.x. It will not work on Kohana 3.x due to the removal of events and hooks. To use autoasset, simply load it like you would any other module, and then go into the config file and specify which kinds of assets to load. Just input the directory that these assets are stored in, the file extension, and a callback to use when rendering. I put in example entries for javascript and css as a demonstration. You can then render the autoloaded assets by calling autoasset::render(); where you want to include the assets, such as the html head tag.</p>
<p>On a similar note, modules like this are one of the main reasons why I am launching <a href="http://visual77.com/blog/tags/ko23">ko23.net</a>. I think Kohana 2.x is a fantastic framework, and if a large community arose to provide modules that are just generally useful, then Kohana 2.x could really shine.</p>
<p><a href="http://visual77.com/blog/wp-content/uploads/2010/09/autoasset.zip">Download Kohana 2.x Autoasset</a></p>
<div class="shr-publisher-638"></div><!-- Start Shareaholic LikeButtonSetBottom --><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://visual77.com/blog/2010/09/kohana-2-x-autoasset-automatically-include-relevant-javascript-css-and-more/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Kohana 2.3 community</title>
		<link>http://visual77.com/blog/2010/09/kohana-2-x-community/</link>
		<comments>http://visual77.com/blog/2010/09/kohana-2-x-community/#comments</comments>
		<pubDate>Tue, 28 Sep 2010 16:03:00 +0000</pubDate>
		<dc:creator>visual77</dc:creator>
				<category><![CDATA[visual77]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://visual77.com/blog/?p=634</guid>
		<description><![CDATA[I&#8217;ve been a Kohana user for about a year now, and every major update pleases me less than the last. I&#8217;m considering starting a community dedicated to Kohana 2.3, built around maintaining documentation (since the official site already pulled the Doxygen docs, how long until they pull the documentation wiki?), creating new modules and generally [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><p>I&#8217;ve been a Kohana user for about a year now, and every major update pleases me less than the last. I&#8217;m considering starting a community dedicated to Kohana 2.3, built around maintaining documentation (since the official site already pulled the Doxygen docs, how long until they pull the documentation wiki?), creating new modules and generally working on preserving the Kohana 2.3 legacy. Would anyone be interested in being a part of this community?</p>
<p>I&#8217;d like to stress that I am in no way trying to insult the developers and maintainers of Kohana through this project. Their work has been absolutely amazing, but just as they forked from CodeIgnitor when they felt it was no longer serving their needs as developers, so now am I feeling that Kohana no longer serves my needs as a developer.</p>
<p>I&#8217;m setting the project up at <a title="Ko23 - Kohana 2.3 Community" href="http://ko23.net/">ko23.net</a>. I&#8217;ll begin adding some functionality such as forums and module hosting / rating.</p>
<div class="shr-publisher-634"></div><!-- Start Shareaholic LikeButtonSetBottom --><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://visual77.com/blog/2010/09/kohana-2-x-community/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Setting up dynamic themes on Kohana</title>
		<link>http://visual77.com/blog/2010/04/kohana-dynamic-theme/</link>
		<comments>http://visual77.com/blog/2010/04/kohana-dynamic-theme/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 18:43:22 +0000</pubDate>
		<dc:creator>visual77</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://visual77.com/blog/?p=584</guid>
		<description><![CDATA[It&#8217;s been a little over six months since I first began to use Kohana framework for all PHP development, and I thoroughly love the system. The only issue I&#8217;ve had with Kohana is the lack of built in, intuitive support for dynamic themes. I was unable to find an easy method to set up a [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><p>It&#8217;s been a little over six months since I first began to use <a href="http://visual77.com/blog/tag/kohana">Kohana</a> framework for all <a href="http://visual77.com/blog/tag/php">PHP</a> development, and I thoroughly love the system. The only issue I&#8217;ve had with Kohana is the lack of built in, intuitive support for dynamic themes. I was unable to find an easy method to set up a theme that automatically wraps itself around all pages, while remaining dynamic enough to change certain elements on a page to page basis.</p>
<p>Over the past few days, I have been exploring methods to do this, with the following requirements:</p>
<ul>
<li>Keep <em>all </em>theme files separate from the application</li>
<li>Require <em>no</em> changes to existing controllers and views to implement or change a theme</li>
<li>Allow multiple applications on the same Kohana build to use the same theme</li>
<li>Provide support for cascading themes</li>
</ul>
<p>After a few failed attempts, I have <a href="http://visual77.com/blog/tag/tutorial">found a solution</a> that covers all four requirements and is pretty easy to implement. Of course, it is easier to implement this from the start, but if you have an existing Kohana site, it shouldn&#8217;t be too difficult to integrate this theming setup into the site. <strong>The concept of the theme is simple: create a theme as a module and then  use hooks to implement the theme elements as appropriate.</strong></p>
<p><span id="more-584"></span></p>
<h3>Step 1 &#8211; Enable hooks</h3>
<p>Without hooks, this theming set up won&#8217;t be able to execute at the proper time, and timing is essential. In order to enable hooks, <strong>open up application/config/config.php and change $config['enable_hooks'] to TRUE</strong>. With hooks enabled, all files within a hooks directory are included. This will be the starting point for inserting the theme content around the template.</p>
<h3>Step 2 &#8211; Create a theme folder</h3>
<p>One of my stated goals for the theme was to keep all theme files inside a single folder. This encapsulation allows for very easy modification, copying and replacing of themes. <strong>Make a folder called themes, and a subfolder named after the theme.</strong> This theme folder will operate just like a module folder, containing config, controllers, hooks, views, etc. My directory tree now looks like this:</p>
<pre>/httpdocs
    /application
    /modules
    /system
    /themes
        /visual77
            /config
            /controllers
            /css
            /hooks
            /images
            /views
    /index.php
</pre>
<h3>Step 3 &#8211; Add the theme folder to the list of enabled modules</h3>
<p>In order to use the theme folder just as a module folder, you need to register the folder in the list of modules being used by your application.<strong> Open up application/config/config.php and add the theme folder to your list of modules at the end.</strong> This lets Kohana make full use of the directory.</p>
<pre class="brush:php">$config['modules'] = array
(
    DOCROOT.'themes/visual77',
);</pre>
<h3><strong> </strong><strong>Step 4 &#8211; Create a hook for adding theme content</strong></h3>
<p>The most important step is creating a hook to add your theme content around your template content. You want to let your template proceed as normal, and after completion, add your theme data.</p>
<p>To create hooks in Kohana, just create a file inside your hooks directory. All files in that directory will be loaded automatically. For instance, <strong>make a file called theme.php inside themes/&lt;theme-name&gt;/hooks.</strong></p>
<p>In order to do the theming, the ideal hook to use is <em>system.post_controller</em>. The previous hook, <em>system.post_controller_constructor</em>, is before the controller has executed; the following hook, <em>system</em>.<em>send_headers</em>, is after <em>system.execute</em>, and therefore can&#8217;t manipulate the controller.</p>
<p>The goal is then to create a hook on <em>system.post_controller</em> and manipulate the controller to take the template data and move it within the overall theme. To access the controller, call Kohana::$instance and begin manipulating. My hook file looks like this:</p>
<pre class="brush:php">&lt;?php defined('SYSPATH') or die('No direct access allowed');

// set my hook up to execute at the appropriate time
event::add('system.post_controller', 'visual77_theme');

function visual77_theme() {
    // grab the controller
    $controller = Kohana::$instance;

    // pull the original template aside
    $temp = $controller-&gt;template;
    // replace the template with my theme template
    $controller-&gt;template = new View('visual77/index');
    // put the original template into the content section of my theme
    $controller-&gt;template-&gt;content = $temp;
    // free up some memory by unsetting the temp variable
    unset($temp);
}
</pre>
<h3><strong>Step 5 &#8211; Begin building the theme</strong></h3>
<p>Now that the hook is in place, the only thing left to do is build your theme. In my example, <strong>create an index.php file in themes/&lt;theme-name&gt;/views/&lt;theme-name&gt;</strong>. This index file will contain the wrapper HTML for your theme, leaving the original template to drop neatly inside the content section that you define. When you begin adding css and images, you can keep it inside the theme directory. The usual .htaccess restriction on modules only applies to the module directory, which is why I put the themes outside of the module folder.</p>
<p>While building, remember to keep all theme related content, such as views and controllers, inside the theme directory. This makes the theme ultra portable and easily removed. To change themes, just change the name of the theme from Step 3 to the new theme directory.</p>
<p>In a system like this, you can even cascade themes. One great example of cascading themes is including barebones files like CSS resets and jQuery files. On a current project, I have to build an internal client administration and an external company website. Both use certain shared libraries and both need a CSS reset and jQuery files. Using cascading themes and module sharing, I can blend these two sites very neatly. The file structure for this project looks like this:</p>
<pre>/httpdocs
    /internal_application
    /external_application
    /modules
        /shared_libraries
    /system
    /themes
        /internal_theme
        /external_theme
        /default
    /index.php
</pre>
<p>Both internal and external applications include modules/shared_libraries and themes/default. However, internal_application also includes themes/internal_theme and external_application includes themes/external_theme. A switch statement in index.php dynamically switches the application based on the hostname. In the end, I  have two sites running smoothly in parallel on a single Kohana build.</p>
<h3>Final Thoughts</h3>
<p>Kohana is a fantastic system, but really needs better support for dynamic theming. In my build process for this theming pattern, I tried to emulate the wordpress theme convention, where all theme files are kept clustered and are easily swapped out for a new theme.</p>
<p>To see a full theme example, you can<strong> <a href="http://visual77.com/blog/wp-content/uploads/2010/04/visual77.zip">download my Sample Kohana Theme</a></strong> and then modify it to fit your needs. Just remember to enable hooks and include this theme as a module!</p>
<div class="shr-publisher-584"></div><!-- Start Shareaholic LikeButtonSetBottom --><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://visual77.com/blog/2010/04/kohana-dynamic-theme/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to flatten an array in PHP</title>
		<link>http://visual77.com/blog/2010/03/php-flatten-array/</link>
		<comments>http://visual77.com/blog/2010/03/php-flatten-array/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 23:57:18 +0000</pubDate>
		<dc:creator>visual77</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://visual77.com/blog/?p=577</guid>
		<description><![CDATA[In a recent Kohana project, I came across a somewhat odd PHP scenario &#8211; I had a multidimensional array that I needed to compress to a single dimensional array, but retaining all of the non array values. Basically, I need to make this change: Array ( to =&#62; Array ( 0 =&#62; stevep 1 =&#62; [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><p>In a recent <a title="Kohana articles" href="http://visual77.com/blog/tag/kohana">Kohana</a> project, I came across a somewhat odd <a title="PHP articles" href="http://visual77.com/blog/tag/php">PHP</a> scenario &#8211; I had a multidimensional array that I needed to compress to a single dimensional array, but retaining all of the non array values. Basically, I need to make this change:</p>
<pre>Array
    (
        to =&gt; Array
            (
                0 =&gt; stevep
                1 =&gt; bobw
            )
        bcc =&gt; Array
            (
                0 =&gt; paulj
            )
    )

Array
    (
        0 =&gt; stevep
        1 =&gt; bobw
        2 =&gt; paulj
    )
</pre>
<p>I looked around a bit for an existing PHP snippet to do just this, but they were all overly complex and used recursive callback functions. I had a feeling I could pull this off in a much more clean fashion. I toyed around a bit with the <a title="PHP:Array Functions" href="http://www.php.net/manual/en/ref.array.php" target="_blank">array functions</a> and the <a title="PHP:ArrayObject" href="http://www.php.net/manual/en/class.arrayobject.php" target="_blank">ArrayObject</a> library, and this is <a title="Tutorials written by Steve Phillips" href="http://visual77.com/blog/tag/tutorial">what I settled with</a>:</p>
<pre class="brush:php">$new_array = new ArrayObject();
array_walk_recursive($old_array, array($new_array, 'offsetSet'));
$flattened_array = array_keys($new_array-&gt;getArrayCopy());
</pre>
<p>The big drawback is the way <a title="PHP:ArrayObject::OffsetSet" href="http://www.php.net/manual/en/arrayobject.offsetset.php" target="_blank">ArrayObect::offsetSet()</a> accepts its parameters, compared to how <a title="PHP:array_walk_recursive" href="http://php.net/manual/en/function.array-walk-recursive.php" target="_blank">array_walk_recursive()</a> sends the callback parameters; they are reversed.  This causes the values to become keys, which has the effect of canceling out duplicate values. If your script needs duplicate values to remain intact, then this solution won&#8217;t work for you. Otherwise, it should work out just fine.</p>
<div class="shr-publisher-577"></div><!-- Start Shareaholic LikeButtonSetBottom --><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://visual77.com/blog/2010/03/php-flatten-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
