<?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>work in progress</title>
	<atom:link href="http://www.workinprogress.ca/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.workinprogress.ca</link>
	<description>of patrick sébastien</description>
	<lastBuildDate>Mon, 07 May 2012 22:37:46 +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>puredata on a tablet</title>
		<link>http://www.workinprogress.ca/puredata-tablet/</link>
		<comments>http://www.workinprogress.ca/puredata-tablet/#comments</comments>
		<pubDate>Mon, 09 Apr 2012 04:14:45 +0000</pubDate>
		<dc:creator>psc</dc:creator>
				<category><![CDATA[Pure Data]]></category>

		<guid isPermaLink="false">http://www.workinprogress.ca/?p=1522</guid>
		<description><![CDATA[here&#8217;s a short video showing puredata running on a ARM v7 / Cortex-A9 tablet (Zenithink c71 aka uPad: 1ghz, 512mb ram). i got this tablet for 144$ CAD. it is possible to connect an arduino to it (via USB) so anyone can &#8220;extend it&#8221; with sensors and such. there&#8217;s also a bluetooth / wifi and [...]]]></description>
			<content:encoded><![CDATA[<p>here&#8217;s a short video showing puredata running on a ARM v7 / Cortex-A9 tablet (Zenithink c71 aka uPad: 1ghz, 512mb ram). i got this tablet for 144$ CAD. it is possible to connect an arduino to it (via USB) so anyone can &#8220;extend it&#8221; with sensors and such. there&#8217;s also a bluetooth / wifi and a 5 points touchscreen. right now alsa is not working (start pd with -oss) and the video driver (mali) is not accelerated.</p>
<p>thanks to xllamas for sharing the <a href="http://www.slatedroid.com/topic/31075-linux-on-the-zt-280-c71/page__p__341999#entry341999">information</a> and also the <a href="http://makeplaylive.com/">http://makeplaylive.com/</a> for the initial work.</p>
<p><iframe width="560" height="315" src="http://www.youtube.com/embed/C-P7Y8bz0bg?rel=0&#038;wmode=transparent" frameborder="0" allowfullscreen></iframe></p>
<p>i am currently working on a new prototype of &#8220;<a href="http://www.workinprogress.ca/projects/guitare-a-crayon/">la guitar à crayon</a>&#8221; called &#8220;string pad&#8221;. bought a guitar kit for 160$. all set to start working on this project.</p>
<p><img src="http://www.workinprogress.ca/wp-content/uploads/stringpad.jpg" alt="" title="stringpad" width="640" height="427" class="alignnone size-medium wp-image-1532" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.workinprogress.ca/puredata-tablet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Online Speech Recognition for Dictation</title>
		<link>http://www.workinprogress.ca/online-speech-recognition-dictation/</link>
		<comments>http://www.workinprogress.ca/online-speech-recognition-dictation/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 05:28:15 +0000</pubDate>
		<dc:creator>psc</dc:creator>
				<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.workinprogress.ca/?p=1231</guid>
		<description><![CDATA[I&#8217;m working on the integration of kiku (voice recognition to control your OS) to Vinux (Linux for the visually impaired). For now the feedback about kiku is great, but one thing people wants is a solution for dictation (that is, speech to text). kiku could be use for that task, but sadly there is no [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.workinprogress.ca/KIKU/dictation.php"><img src="http://www.workinprogress.ca/wp-content/uploads/onlinespeechrecognitiondictation-1024x554.png" alt="" title="onlinespeechrecognitiondictation" width="512" height="277" class="alignnone size-large wp-image-1233" /></a></p>
<p>I&#8217;m working on the integration of <a href="http://www.workinprogress.ca/kiku/about">kiku</a> <em>(voice recognition to control your OS)</em> to <a href="http://vinuxproject.org/">Vinux</a> <em>(Linux for the visually impaired)</em>. For now the feedback about kiku is great, but one thing people wants is a solution for dictation (that is, speech to text). kiku could be use for that task, but sadly there is no good (accurate) acoustic model available under GPL (Voxforge is a good start, but not there yet &#8211; please <a href="http://www.voxforge.org/home/read">contribute</a>).</p>
<p>So i came up with this <a href="http://www.workinprogress.ca/KIKU/dictation.php">online speech recognition for dictation</a> solution to overcome this limitation. Speak in different languages, spell check, translate and text to speech all in one place. You&#8217;ll need <a href="http://www.google.com/chrome">Google Chrome</a> and a microphone.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="540" height="405" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/D5rNrfufHmw&amp;hl=en_US&amp;fs=1?rel=0&amp;hd=1" /><param name="allowfullscreen" value="true" /><param name="wmode" value="transparent" /><embed type="application/x-shockwave-flash" width="540" height="405" src="http://www.youtube.com/v/D5rNrfufHmw&amp;hl=en_US&amp;fs=1?rel=0&amp;hd=1" wmode="transparent" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.workinprogress.ca/online-speech-recognition-dictation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>p-waves physical feedback</title>
		<link>http://www.workinprogress.ca/p-waves-physical-feedback/</link>
		<comments>http://www.workinprogress.ca/p-waves-physical-feedback/#comments</comments>
		<pubDate>Thu, 24 Mar 2011 17:16:22 +0000</pubDate>
		<dc:creator>psc</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://www.workinprogress.ca/?p=1136</guid>
		<description><![CDATA[on march 11 my apartment in tokyo was shook by an earthquake of magnitude 9.0: since i don&#8217;t have a mobile phone (i must be the only one in japan without a keitai) i wasn&#8217;t aware of the incoming earthquake and my software was useless (being alert 10 minutes after the earthquake): by detecting the [...]]]></description>
			<content:encoded><![CDATA[<p>on march 11 my apartment in tokyo was shook by an earthquake of magnitude 9.0:</p>
<p><iframe title="YouTube video player" width="560" height="349" src="http://www.youtube.com/embed/i6U-N0W5Zkc?rel=0&#038;wmode=transparent" frameborder="0" allowfullscreen></iframe></p>
<p>since i don&#8217;t have a mobile phone (i must be the only one in japan without a keitai) i wasn&#8217;t aware of the incoming earthquake and my software was useless (being alert 10 minutes after the earthquake):</p>
<p><iframe src="http://player.vimeo.com/video/13615727" width="560" height="315" frameborder="0"></iframe></p>
<p>by detecting the <a href="http://en.wikipedia.org/wiki/Seismic_wave#P-waves">primary waves</a> we know in how many seconds (depending on the epicenter location) an earthquake will occur. i don&#8217;t know if it&#8217;s possible to build a p waves monitoring device (anyone?), but for now i&#8217;m using a <a href="http://www.estrat.co.jp/download.html">free software</a> (windows &#038; japanese only) that send me an alert (no hardware required).</p>
<p>connecting the software to a microcontroller was not that hard, but since i don&#8217;t want to boot in windows just for monitoring the p waves i had to hack little. grosso modo: <a href="http://www.virtualbox.org/">virtual box</a> (windows in linux) -> <a href="http://www.autoitscript.com/site/autoit/">autoit</a> (checking for a p waves popup) -> create file <- linux bash checking for new file -> send serial command to arduino -> physical feedback.</p>
<p><iframe title="YouTube video player" width="560" height="349" src="http://www.youtube.com/embed/oiP9QCS-8ig?rel=0&#038;wmode=transparent" frameborder="0" allowfullscreen></iframe></p>
<p><strong>please make a donation to the japanese red cross society</strong></p>
<p><a href="http://www.google.com/crisisresponse/japanquake2011.html"><img border="0" src="http://www.redcross.org/www-files/psabanners/PacificTsunami/468x60.jpg" alt="Japan Earthquake and Pacific Tsunami"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.workinprogress.ca/p-waves-physical-feedback/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>vibrating art</title>
		<link>http://www.workinprogress.ca/vibrating-art/</link>
		<comments>http://www.workinprogress.ca/vibrating-art/#comments</comments>
		<pubDate>Sun, 19 Dec 2010 18:23:16 +0000</pubDate>
		<dc:creator>psc</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://www.workinprogress.ca/?p=876</guid>
		<description><![CDATA[the idea is simple: take an old electric toothbrush; add a led and a vibrator; shape something around it; i am using polycaprolactone (FDA approuved). the schematic is pretty simple, but i had to play with the capacitor and inductor to get more power into the vibrator. it&#8217;s overkill to use an attiny for cycling [...]]]></description>
			<content:encoded><![CDATA[<p>the idea is simple:</p>
<ul>
<li>take an old electric toothbrush;</li>
<li>add a led and a vibrator;</li>
<li>shape something around it;</li>
</ul>
<p>i am using polycaprolactone (FDA approuved). the schematic is pretty simple, but i had to play with the capacitor and inductor to get more power into the vibrator. it&#8217;s overkill to use an attiny for cycling the colors of the led (i didn&#8217;t know that you can buy RGB led with built-in pwm). even so, i am sharing the small code, maybe it can be useful to someone. since i am using an electric toothbrush there&#8217;s no physical connection to recharge it, thus completely waterproof. i will need to remelt the polycaprolactone to change the battery someday.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="540" height="405" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/vE1pPWRUmbs&amp;hl=en_US&amp;fs=1?rel=0&amp;hd=1" /><param name="allowfullscreen" value="true" /><param name="wmode" value="transparent" /><embed type="application/x-shockwave-flash" width="540" height="405" src="http://www.youtube.com/v/vE1pPWRUmbs&amp;hl=en_US&amp;fs=1?rel=0&amp;hd=1" wmode="transparent" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>

<a href='http://www.workinprogress.ca/vibrating-art/va_bundle/' title='va_bundle'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/va_bundle-150x150.jpg" class="attachment-thumbnail" alt="va_bundle" title="va_bundle" /></a>
<a href='http://www.workinprogress.ca/vibrating-art/va_onrecharge/' title='va_onrecharge'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/va_onrecharge-150x150.jpg" class="attachment-thumbnail" alt="va_onrecharge" title="va_onrecharge" /></a>
<a href='http://www.workinprogress.ca/vibrating-art/va_schematic/' title='va_schematic'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/va_schematic-150x150.jpg" class="attachment-thumbnail" alt="va_schematic" title="va_schematic" /></a>
<a href='http://www.workinprogress.ca/vibrating-art/va_withvl/' title='va_withvl'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/va_withvl-150x150.jpg" class="attachment-thumbnail" alt="va_withvl" title="va_withvl" /></a>

<p></p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"> <span style="color: #339933;">#define F_CPU 9600000UL</span>
 <span style="color: #339933;">#include &lt;avr/io.h&gt;</span>
 <span style="color: #339933;">#include &lt;util/delay.h&gt;</span>
 <span style="color: #339933;">#define LED PB0</span>
 <span style="color: #339933;">#define LED2 PB1</span>
 <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #993333;">int</span> main <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
	 DDRB <span style="color: #339933;">=</span> <span style="color: #208080;">0xff</span><span style="color: #339933;">;</span>
	 TCCR0A <span style="color: #339933;">|=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> COM0A1<span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> COM0A0<span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> COM0B1<span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> COM0B0<span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> WGM01<span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> WGM00<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// WGM01 - WGM00 (set fast PWM)</span>
	 OCR0A <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// initialize Output Compare Register A to 0</span>
	 OCR0B <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	 TCCR0B <span style="color: #339933;">|=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> CS01<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Start timer at Fcpu / 256</span>
&nbsp;
	 <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">;;</span><span style="color: #009900;">&#41;</span>
	 <span style="color: #009900;">&#123;</span>
		 <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">255</span> <span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// For loop (Up counter 0 - 255)</span>
		 <span style="color: #009900;">&#123;</span>
			  OCR0A <span style="color: #339933;">=</span> i<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Update Output Compare Register (PWM 0 - 255)</span>
			 _delay_ms<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		 <span style="color: #009900;">&#125;</span>
		 <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">255</span> <span style="color: #339933;">;</span> i <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">1</span> <span style="color: #339933;">;</span> i<span style="color: #339933;">--</span> <span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// For loop (down counter 255 - 0 )</span>
		 <span style="color: #009900;">&#123;</span>
			 OCR0B <span style="color: #339933;">=</span> i<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Update Output Compare Register (PWM 0 - 255)</span>
			 _delay_ms<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		 <span style="color: #009900;">&#125;</span>
		 <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">255</span> <span style="color: #339933;">;</span> i <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">1</span> <span style="color: #339933;">;</span> i<span style="color: #339933;">--</span> <span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// For loop (down counter 255 - 0 )</span>
		 <span style="color: #009900;">&#123;</span>
			  OCR0A <span style="color: #339933;">=</span> i<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Update Output Compare Register (PWM 0 - 255)</span>
			 _delay_ms<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		 <span style="color: #009900;">&#125;</span>
		 <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">255</span> <span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// For loop (Up counter 0 - 255)</span>
		 <span style="color: #009900;">&#123;</span>
			  OCR0B <span style="color: #339933;">=</span> i<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Update Output Compare Register (PWM 0 - 255)</span>
			 _delay_ms<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		 <span style="color: #009900;">&#125;</span>
	 <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.workinprogress.ca/vibrating-art/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>video tour of akihabara</title>
		<link>http://www.workinprogress.ca/video-tour-of-akihabara/</link>
		<comments>http://www.workinprogress.ca/video-tour-of-akihabara/#comments</comments>
		<pubDate>Sat, 25 Sep 2010 02:55:29 +0000</pubDate>
		<dc:creator>psc</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://www.workinprogress.ca/?p=820</guid>
		<description><![CDATA[if you are curious to see the electronic town (Akihabara) in Tokyo:]]></description>
			<content:encoded><![CDATA[<p>if you are curious to see the electronic town (Akihabara) in Tokyo:<br />
<a href="http://www.workinprogress.ca/akihabara"><img class="alignnone size-full wp-image-821" title="akihabara" src="http://www.workinprogress.ca/wp-content/uploads/akihabara.jpg" alt="" width="533" height="454" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.workinprogress.ca/video-tour-of-akihabara/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Manabu-san</title>
		<link>http://www.workinprogress.ca/manabu-san/</link>
		<comments>http://www.workinprogress.ca/manabu-san/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 13:13:44 +0000</pubDate>
		<dc:creator>psc</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.workinprogress.ca/?p=790</guid>
		<description><![CDATA[I wrote this software (based on JMDict) to learn new words in japanese. It&#8217;s written in C++ (wxWidgets) and use sqlite3. A compiled version for Windows is available for download (with installer / uninstaller). I am sharing the source, but i won&#8217;t recommend to learn from it (a cobe::blocks project). Here&#8217;s a screenshot in Windows: Here&#8217;s a [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote this software (based on<a href="http://www.csse.monash.edu.au/~jwb/j_jmdict.html" target="_blank"> JMDict</a>) to learn new words in japanese. It&#8217;s written in C++ (<a href="http://www.wxwidgets.org/" target="_blank">wxWidgets</a>) and use <a href="http://www.sqlite.org/" target="_blank">sqlite3</a>. A compiled version for Windows is available for download (with installer / uninstaller). I am sharing the source, but i won&#8217;t recommend to learn from it (a <a href="http://www.codeblocks.org/" target="_blank">cobe::blocks</a> project).</p>
<p>Here&#8217;s a screenshot in Windows:</p>
<p><a href="http://www.workinprogress.ca/wp-content/uploads/manabu-san.jpg"></a><a href="http://www.workinprogress.ca/wp-content/uploads/manabu-san.jpg"><img class="alignnone size-large wp-image-791" title="manabu-san" src="http://www.workinprogress.ca/wp-content/uploads/manabu-san-1024x710.jpg" alt="" width="500" height="347" /></a></p>
<p>Here&#8217;s a screenshot in Ubuntu / Gtk:</p>
<p><a href="http://www.workinprogress.ca/wp-content/uploads/manabu-san-linux.jpg"><img class="alignnone size-large wp-image-804" title="manabu-san-linux" src="http://www.workinprogress.ca/wp-content/uploads/manabu-san-linux-1024x692.jpg" alt="" width="500" height="338" /></a></p>
<p><a href="http://www.workinprogress.ca/wp-content/uploads/setup.exe">Download the installer</a> (for Windows, beta)<br />
<a href="http://www.workinprogress.ca/wp-content/uploads/manabu_src.zip">Download the source</a> (code::blocks)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.workinprogress.ca/manabu-san/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>cheap avr intervalometer</title>
		<link>http://www.workinprogress.ca/avr-intervalometer/</link>
		<comments>http://www.workinprogress.ca/avr-intervalometer/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 08:38:21 +0000</pubDate>
		<dc:creator>psc</dc:creator>
				<category><![CDATA[Blender]]></category>
		<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://www.workinprogress.ca/?p=755</guid>
		<description><![CDATA[now that i have a digital camera (but my heart will always belong to film-based photography) i can do time lapse photography. sadly the firmware of my camera isn&#8217;t supporting this feature, so i had to build an intervalometer. i didn&#8217;t want to use an arduino (overkill &#38; pricy), so i went with an attiny45, [...]]]></description>
			<content:encoded><![CDATA[<p>now that i have a digital camera (but my heart will always belong to film-based photography) i can do time lapse photography. sadly the firmware of my camera isn&#8217;t supporting this feature, so i had to build an <a href="http://en.wikipedia.org/wiki/Intervalometer" target="_blank">intervalometer</a>. i didn&#8217;t want to use an arduino (overkill &amp; pricy), so i went with an attiny45, a generic optocoupler, a voltage regulator and a potentiometer for adjusting the timer from 1 second to 1 minute.</p>
<p>i just found out that it&#8217;s possible to power the avr from the camera (focus ring). have a look at this complete and small solution: <a href="http://www.doc-diy.net/photo/hdr-jack/">http://www.doc-diy.net/photo/hdr-jack/</a></p>

<a href='http://www.workinprogress.ca/avr-intervalometer/intervalometer_1/' title='intervalometer_1'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/intervalometer_1-150x150.jpg" class="attachment-thumbnail" alt="intervalometer_1" title="intervalometer_1" /></a>
<a href='http://www.workinprogress.ca/avr-intervalometer/intervalometer_3/' title='intervalometer_3'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/intervalometer_3-150x150.jpg" class="attachment-thumbnail" alt="intervalometer_3" title="intervalometer_3" /></a>
<a href='http://www.workinprogress.ca/avr-intervalometer/avr_intervalometer_schematic/' title='avr_intervalometer_schematic'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/avr_intervalometer_schematic-150x150.png" class="attachment-thumbnail" alt="avr_intervalometer_schematic" title="avr_intervalometer_schematic" /></a>


<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Intervalometer from 1 second to 1 minute</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Author: Patrick Sebastien Coulombe</span>
<span style="color: #666666; font-style: italic;">//Website: www.workinprogress.ca</span>
<span style="color: #666666; font-style: italic;">//Date: 2010-07-24</span>
&nbsp;
<span style="color: #339933;">#define F_CPU 8000000</span>
<span style="color: #339933;">#include &lt;avr/io.h&gt;</span>
<span style="color: #339933;">#include &lt;util/delay.h&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// use PB2 for led, pin 7</span>
<span style="color: #339933;">#define LED_BIT 2</span>
<span style="color: #666666; font-style: italic;">// select ADC2, PB4, pin 3</span>
<span style="color: #339933;">#define CHANNEL 2</span>
<span style="color: #666666; font-style: italic;">// shutter on (in ms)</span>
<span style="color: #339933;">#define HOLD 300 </span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Return the 10bit value of the selected adc channel.</span>
<span style="color: #993333;">uint16_t</span> get_adc<span style="color: #009900;">&#40;</span><span style="color: #993333;">uint8_t</span> channel<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// ADC setup</span>
	ADCSRA <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> ADEN<span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> ADPS1<span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> ADPS0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// select channel</span>
	ADMUX <span style="color: #339933;">=</span> channel<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// warm up the ADC, discard the first conversion</span>
	ADCSRA <span style="color: #339933;">|=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> ADSC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>ADCSRA <span style="color: #339933;">&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> ADSC<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
	ADCSRA <span style="color: #339933;">|=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> ADSC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// start single conversion</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>ADCSRA <span style="color: #339933;">&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> ADSC<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// wait until conversion is done</span>
&nbsp;
	<span style="color: #b1b100;">return</span> ADCW<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Scale</span>
<span style="color: #993333;">long</span> map<span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span> x<span style="color: #339933;">,</span> <span style="color: #993333;">long</span> in_min<span style="color: #339933;">,</span> <span style="color: #993333;">long</span> in_max<span style="color: #339933;">,</span> <span style="color: #993333;">long</span> out_min<span style="color: #339933;">,</span> <span style="color: #993333;">long</span> out_max<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span>x <span style="color: #339933;">-</span> in_min<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>out_max <span style="color: #339933;">-</span> out_min<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span>in_max <span style="color: #339933;">-</span> in_min<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> out_min<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Main program</span>
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// vars</span>
	<span style="color: #993333;">uint16_t</span> adcvalue <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">uint16_t</span> i<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// define LED as outputs</span>
	DDRB <span style="color: #339933;">|=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> LED_BIT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	
&nbsp;
		<span style="color: #666666; font-style: italic;">//release the shutter</span>
		PORTB <span style="color: #339933;">|=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> LED_BIT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//exposure length</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>HOLD<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			_delay_ms<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span>
		PORTB <span style="color: #339933;">&amp;=</span> ~<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> LED_BIT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//interval time (using a potentiometer to adjust)</span>
		adcvalue <span style="color: #339933;">=</span> map<span style="color: #009900;">&#40;</span>get_adc<span style="color: #009900;">&#40;</span>CHANNEL<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1023</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		adcvalue <span style="color: #339933;">=</span> adcvalue <span style="color: #339933;">*</span> <span style="color: #0000dd;">1000</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//one way to achieve long delay</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>adcvalue<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			_delay_ms<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Time lapse test (3 hours) from my balcony.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="540" height="405" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="wmode" value="transparent" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/mKEQjxkCzD4&amp;hl=en_US&amp;fs=1?rel=0&amp;hd=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="540" height="405" src="http://www.youtube.com/v/mKEQjxkCzD4&amp;hl=en_US&amp;fs=1?rel=0&amp;hd=1" allowscriptaccess="always" allowfullscreen="true" wmode="transparent"></embed></object></p>
<p>I used Blender for making the tilt / shift effect. Here&#8217;s the <a href="http://www.workinprogress.ca/wp-content/uploads/blendertiltshift.tar.gz">source</a> of the Blender file.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="540" height="405" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="wmode" value="transparent" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/qpac5wb7mAE&amp;hl=en_US&amp;fs=1?rel=0&amp;hd=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="540" height="405" src="http://www.youtube.com/v/qpac5wb7mAE&amp;hl=en_US&amp;fs=1?rel=0&amp;hd=1" allowscriptaccess="always" allowfullscreen="true" wmode="transparent"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.workinprogress.ca/avr-intervalometer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>singing birds</title>
		<link>http://www.workinprogress.ca/singing-birds/</link>
		<comments>http://www.workinprogress.ca/singing-birds/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 04:36:59 +0000</pubDate>
		<dc:creator>psc</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://www.workinprogress.ca/?p=706</guid>
		<description><![CDATA[10 watts amplifier with built-in 16-bit / 48kHz RIFF-WAVE player (music on a SD-CARD). 2 servos for controlling the beaks. I did this project mostly to learn stuff. The result is a bit stupid. VIDEO: PHOTOS: Schematic &#038; Board (Kicad) How to filter PWM for music sd player source code /*---------------------------------------------------------------*/ /* 8-pin SD audio [...]]]></description>
			<content:encoded><![CDATA[<p>10 watts amplifier with built-in 16-bit / 48kHz RIFF-WAVE player (<a href="http://elm-chan.org/works/sd8p/report.html" target="_blank">music on a SD-CARD</a>). 2 servos for controlling the beaks. I did this project mostly to learn stuff. The result is a bit stupid.</p>
<p><strong>VIDEO:</strong><br />
<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/rEM_cyZhxQU?fs=1&amp;hl=en_US&amp;rel=0"></param><param name="wmode" value="transparent" /></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/rEM_cyZhxQU?fs=1&amp;hl=en_US&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" wmode="transparent" allowfullscreen="true" width="480" height="385"></embed></object></p>
<p><strong>PHOTOS:</strong><br />

<a href='http://www.workinprogress.ca/singing-birds/p4120089/' title='passive crossover'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/P4120089-150x150.jpg" class="attachment-thumbnail" alt="passive crossover" title="passive crossover" /></a>
<a href='http://www.workinprogress.ca/singing-birds/p4130093/' title='back - 2 mini servo'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/P4130093-150x150.jpg" class="attachment-thumbnail" alt="back - 2 mini servo" title="back - 2 mini servo" /></a>
<a href='http://www.workinprogress.ca/singing-birds/p4130094/' title='single-side homemade PCB'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/P4130094-150x150.jpg" class="attachment-thumbnail" alt="single-side homemade PCB" title="single-side homemade PCB" /></a>
<a href='http://www.workinprogress.ca/singing-birds/p4130095/' title='front'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/P4130095-150x150.jpg" class="attachment-thumbnail" alt="front" title="front" /></a>
<a href='http://www.workinprogress.ca/singing-birds/blender/' title='i used blender like a CAD software'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/blender-150x150.jpg" class="attachment-thumbnail" alt="i used blender like a CAD software" title="i used blender like a CAD software" /></a>
<a href='http://www.workinprogress.ca/singing-birds/board/' title='attiny85 - attiny24 - tpa1517ne - pwm filter - opamp'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/board-150x150.jpg" class="attachment-thumbnail" alt="attiny85 - attiny24 - tpa1517ne - pwm filter - opamp" title="attiny85 - attiny24 - tpa1517ne - pwm filter - opamp" /></a>
<a href='http://www.workinprogress.ca/singing-birds/schematic-2/' title='schematic - done in kicad'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/schematic1-150x150.jpg" class="attachment-thumbnail" alt="schematic - done in kicad" title="schematic - done in kicad" /></a>
</p>
<p>
<a href="http://www.workinprogress.ca/wp-content/uploads/sb.zip">Schematic &#038; Board</a> (Kicad)<br />
<a href="http://www.workinprogress.ca/filtering-pwm-for-music/">How to filter PWM for music</a>
</p>
<p>sd player source code</p>
<p><pre><pre class="brush:c">
/*---------------------------------------------------------------*/
/* 8-pin SD audio player R0.02&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (C)ChaN, 2009 */
/*---------------------------------------------------------------*/

#include &lt;avr/io.h&gt;
#include &lt;avr/interrupt.h&gt;
#include &lt;avr/sleep.h&gt;
#include &lt;avr/wdt.h&gt;
#include &lt;string.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &quot;diskio.h&quot;
#include &quot;pff.h&quot;

char strbuff[10];
unsigned int position = 0;
unsigned long count = 0;
unsigned int nbwave = 0;

#define FCC(c1,c2,c3,c4)&nbsp;&nbsp;(((DWORD)c4&lt;&lt;24)+((DWORD)c3&lt;&lt;16)+((WORD)c2&lt;&lt;8)+(BYTE)c1)&nbsp;&nbsp;/* FourCC */

/*---------------------------------------------------------*/
/* Work Area&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */
/*---------------------------------------------------------*/

volatile BYTE FifoRi, FifoWi, FifoCt;&nbsp;&nbsp;/* FIFO controls */

BYTE Buff[256];&nbsp;&nbsp;&nbsp;&nbsp;/* Wave output FIFO */

FATFS fs;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* File system object */
DIR dir;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Directory object */
FILINFO fno;&nbsp;&nbsp;&nbsp;&nbsp;/* File information */

WORD rb;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Return value. Put this here to avoid bugs of avr-gcc */

EMPTY_INTERRUPT(WDT_vect);

/*---------------------------------------------------------*/

static
DWORD load_header (void)&nbsp;&nbsp;/* 0:Invalid format, 1:I/O error, &gt;1:Number of samples */
{
&nbsp;&nbsp;DWORD fcc, sz;
&nbsp;&nbsp;UINT i;
&nbsp;&nbsp;FRESULT res;

&nbsp;&nbsp;res = pf_read(Buff, 256, &amp;rb);&nbsp;&nbsp;&nbsp;&nbsp;/* Load file header (256 bytes) */
&nbsp;&nbsp;if (res) return 1;

&nbsp;&nbsp;if (rb != 256 || LD_DWORD(Buff+8) != FCC(&#039;W&#039;,&#039;A&#039;,&#039;V&#039;,&#039;E&#039;)) return 0;

&nbsp;&nbsp;i = 12;
&nbsp;&nbsp;while (i &lt; 200) {
&nbsp;&nbsp;&nbsp;&nbsp;fcc = LD_DWORD(&amp;Buff[i]);&nbsp;&nbsp;/* FCC */
&nbsp;&nbsp;&nbsp;&nbsp;sz = LD_DWORD(&amp;Buff[i+4]);&nbsp;&nbsp;/* Chunk size */
&nbsp;&nbsp;&nbsp;&nbsp;i += 8;
&nbsp;&nbsp;&nbsp;&nbsp;switch (fcc) {

&nbsp;&nbsp;&nbsp;&nbsp;case FCC(&#039;f&#039;,&#039;m&#039;,&#039;t&#039;,&#039; &#039;) :&nbsp;&nbsp;&nbsp;&nbsp;/* &#039;fmt &#039; chunk */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (sz &gt; 100 || sz &lt; 16)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Check chunk size */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (Buff[i+0] != 1)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Check coding type (1) */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (Buff[i+2] != 1 &amp;&amp; Buff[i+2] != 2)&nbsp;&nbsp;/* Check channels (1/2) */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GPIOR0 = Buff[i+2];&nbsp;&nbsp;&nbsp;&nbsp;/* Channel flag */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (Buff[i+14] != 8 &amp;&amp; Buff[i+14] != 16)&nbsp;&nbsp;/* Check resolution (8/16) */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GPIOR0 |= Buff[i+14];&nbsp;&nbsp;/* Resolution flag */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OCR0A = (BYTE)(F_CPU / 8 / LD_WORD(&amp;Buff[i+4])) - 1;&nbsp;&nbsp;/* Sampling freq */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;

&nbsp;&nbsp;&nbsp;&nbsp;case FCC(&#039;f&#039;,&#039;a&#039;,&#039;c&#039;,&#039;t&#039;) :&nbsp;&nbsp;&nbsp;&nbsp;/* &#039;fact&#039; chunk (skip) */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;

&nbsp;&nbsp;&nbsp;&nbsp;case FCC(&#039;d&#039;,&#039;a&#039;,&#039;t&#039;,&#039;a&#039;) :&nbsp;&nbsp;&nbsp;&nbsp;/* &#039;data&#039; chunk (start to play) */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fs.fptr = i;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return sz;

&nbsp;&nbsp;&nbsp;&nbsp;default :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Unknown chunk (error) */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;i += sz;
&nbsp;&nbsp;}

&nbsp;&nbsp;return 0;
}

static
UINT play (
&nbsp;&nbsp;const char *fn
)
{
&nbsp;&nbsp;DWORD sz;
&nbsp;&nbsp;FRESULT res;
&nbsp;&nbsp;BYTE sw;
&nbsp;&nbsp;WORD btr;

&nbsp;&nbsp;if ((res = pf_open(fn)) == FR_OK) {
&nbsp;&nbsp;&nbsp;&nbsp;sz = load_header();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Load file header */
&nbsp;&nbsp;&nbsp;&nbsp;if (sz &lt; 256) return (UINT)sz;

&nbsp;&nbsp;&nbsp;&nbsp;if (!TCCR1) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Enable audio out if not enabled */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PLLCSR = 0b00000110;&nbsp;&nbsp;/* Select PLL clock for TC1.ck */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GTCCR =&nbsp;&nbsp;0b01100000;&nbsp;&nbsp;/* Enable TC1.OCB as PWM out (L-ch) */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OCR1B = 128; OCR1A = 128;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TCCR1 = STEREO ? 0b01100001 : 0b00000001;&nbsp;&nbsp;/* Start TC1 with TC1.OCA is enabled as PWM out (R-ch) */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TCCR0A = 0b00000010;&nbsp;&nbsp;/* Enable TC0.ck = 2MHz as interval timer */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TCCR0B = 0b00000010;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIMSK = _BV(OCIE0A);
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;FifoCt = 0; FifoRi = 0; FifoWi = 0;&nbsp;&nbsp;&nbsp;&nbsp;/* Reset FIFO */
&nbsp;&nbsp;&nbsp;&nbsp;pf_read(0, 512 - fs.fptr, &amp;rb);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Snip sector unaligned part */
&nbsp;&nbsp;&nbsp;&nbsp;sz -= rb;

&nbsp;&nbsp;&nbsp;&nbsp;sw = 1;&nbsp;&nbsp;&nbsp;&nbsp;/* Button status flag */
&nbsp;&nbsp;&nbsp;&nbsp;do {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Forward audio data */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;btr = (sz &gt; 1024) ? 1024 : (WORD)sz;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res = pf_read(0, btr, &amp;rb);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (res != FR_OK || btr != rb) break;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sz -= rb;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Check button down and break on button down */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sw &lt;&lt;= 1;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//if (bit_is_clear(PINB, 0) &amp;&amp; ++sw == 1) break;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (bit_is_clear(PINB, 0) &amp;&amp; ++sw == 1) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count = 0;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do { 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count++;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wdt_reset();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} while (bit_is_clear(PINB, 0));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(count &gt; 500000) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;position--;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;position--;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wdt_reset();
&nbsp;&nbsp;&nbsp;&nbsp;} while (rb == 1024);&nbsp;&nbsp;/* Repeat until all data read */
&nbsp;&nbsp;}

&nbsp;&nbsp;while (FifoCt) ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Wait for FIFO empty */
&nbsp;&nbsp;OCR1A = 128; OCR1B = 128;

&nbsp;&nbsp;return res;
}

long smallrandom(long howbig)
{
&nbsp;&nbsp;if (howbig == 0) {
&nbsp;&nbsp;&nbsp;&nbsp;return 0;
&nbsp;&nbsp;}
&nbsp;&nbsp;return random() % howbig;
}

long rangerandom(long howsmall, long howbig)
{
&nbsp;&nbsp;if (howsmall &gt;= howbig) {
&nbsp;&nbsp;&nbsp;&nbsp;return howsmall;
&nbsp;&nbsp;}
&nbsp;&nbsp;long diff = howbig - howsmall;
&nbsp;&nbsp;return smallrandom(diff) + howsmall;
}

int main (void)
{
&nbsp;&nbsp;PORTB = 0b111011;&nbsp;&nbsp;&nbsp;&nbsp;/* Initialize port: - - H H H L H P */
&nbsp;&nbsp;DDRB&nbsp;&nbsp;= 0b111110;
&nbsp;&nbsp;
&nbsp;&nbsp;sei();
&nbsp;&nbsp;
&nbsp;&nbsp;//RANDOM (SEED)
&nbsp;&nbsp;unsigned long seednumber = 1;
&nbsp;&nbsp;unsigned char i;
&nbsp;&nbsp;ADCSRA |= (1 &lt;&lt; ADPS2) | (1 &lt;&lt; ADPS1) | (0 &lt;&lt; ADPS0);&nbsp;&nbsp;//ADC Prescalar set to 64 - 125kHz@8MHz
&nbsp;&nbsp;ADMUX |= (1 &lt;&lt; ADLAR);
&nbsp;&nbsp;ADCSRA |= (1 &lt;&lt; ADEN);&nbsp;&nbsp;// Enable ADC
&nbsp;&nbsp;&nbsp;&nbsp;for(i = 0; i &lt; 100; i++) {
&nbsp;&nbsp;&nbsp;&nbsp;wdt_reset();
&nbsp;&nbsp;&nbsp;&nbsp;ADCSRA |= (1 &lt;&lt; ADSC);&nbsp;&nbsp;// Start A2D Conversions
&nbsp;&nbsp;&nbsp;&nbsp;while (ADCSRA &amp; (1 &lt;&lt; ADSC)); 
&nbsp;&nbsp;&nbsp;&nbsp;seednumber = seednumber + ADCH;
&nbsp;&nbsp;}
&nbsp;&nbsp;ADCSRA |= (0 &lt;&lt; ADATE);
&nbsp;&nbsp;ADCSRA |= (0 &lt;&lt; ADEN);&nbsp;&nbsp;// Disable ADC
&nbsp;&nbsp;&nbsp;&nbsp;ADCSRA |= (0 &lt;&lt; ADSC);&nbsp;&nbsp;// Stop A2D Conversions
&nbsp;&nbsp;
&nbsp;&nbsp;MCUSR = 0;
&nbsp;&nbsp;WDTCR = _BV(WDE) | 0b110;&nbsp;&nbsp;/* Enable WDT reset in timeout of 1s */

&nbsp;&nbsp;BYTE res;
&nbsp;&nbsp;//mount
&nbsp;&nbsp;do {
&nbsp;&nbsp;&nbsp;&nbsp;res = pf_mount(&amp;fs);
&nbsp;&nbsp;&nbsp;&nbsp;wdt_reset();
&nbsp;&nbsp;&nbsp;&nbsp;seednumber++;
&nbsp;&nbsp;} while (res != FR_OK);
&nbsp;&nbsp;
&nbsp;&nbsp;Buff[0] = 0;
&nbsp;&nbsp;do {
&nbsp;&nbsp;&nbsp;&nbsp;res = pf_opendir(&amp;dir, (char*)Buff);
&nbsp;&nbsp;&nbsp;&nbsp;wdt_reset();
&nbsp;&nbsp;&nbsp;&nbsp;seednumber++;
&nbsp;&nbsp;} while (res != FR_OK);
&nbsp;&nbsp;
&nbsp;&nbsp;//nb files
&nbsp;&nbsp;for (;;) {
&nbsp;&nbsp;&nbsp;&nbsp;res = pf_readdir(&amp;dir, &amp;fno);
&nbsp;&nbsp;&nbsp;&nbsp;if (res != FR_OK || fno.fname[0] == 0) break;
&nbsp;&nbsp;&nbsp;&nbsp;wdt_reset();
&nbsp;&nbsp;&nbsp;&nbsp;nbwave++;
&nbsp;&nbsp;&nbsp;&nbsp;seednumber++;
&nbsp;&nbsp;}
&nbsp;&nbsp;
&nbsp;&nbsp;srandom(seednumber);
&nbsp;&nbsp;//start with a random position
&nbsp;&nbsp;position = rangerandom(1, nbwave + 1);

&nbsp;&nbsp;for (;;) {
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;//limit
&nbsp;&nbsp;&nbsp;&nbsp;if(position &gt; (nbwave + 1)) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;position = 1;
&nbsp;&nbsp;&nbsp;&nbsp;} else if(position &lt; 1) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;position = 1;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;//play
&nbsp;&nbsp;&nbsp;&nbsp;sprintf(strbuff,&quot;%d.wav&quot;, position);
&nbsp;&nbsp;&nbsp;&nbsp;play(strbuff);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;//increment song
&nbsp;&nbsp;&nbsp;&nbsp;position++;

&nbsp;&nbsp;}
}
</pre></pre></p>
<p>servo source code</p>
<p><pre><pre class="brush:c">
#include &lt;avr/io.h&gt;
#include &lt;avr/interrupt.h&gt;
#include &lt;inttypes.h&gt;
#include &lt;avr/sleep.h&gt;
#include &lt;util/delay.h&gt; 

#define F_CPU 8000000
#define nop()&nbsp;&nbsp;__asm__ __volatile__(&quot;nop&quot;)

void wait100us(void) {
&nbsp;&nbsp;&nbsp;&nbsp;unsigned char i;
&nbsp;&nbsp;&nbsp;&nbsp;for(i = 0; i &lt; 100; i++) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nop();
&nbsp;&nbsp;&nbsp;&nbsp;}
}

void Delay_ms(unsigned int t)

&nbsp;&nbsp;{
&nbsp;&nbsp; unsigned int i, aika;
&nbsp;&nbsp; aika = 140;

&nbsp;&nbsp; while(t--)
&nbsp;&nbsp;&nbsp;&nbsp;for(i = 0; i &lt; aika; i++)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(t==0) return;

&nbsp;&nbsp;} 

void adcinit (void) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// PRESCALER 128
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ADCSRA |= (1 &lt;&lt; ADPS2) | (1 &lt;&lt; ADPS1) | (0 &lt;&lt; ADPS0);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// AUTO TRIGGER ENABLE
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ADCSRA |= (1 &lt;&lt; ADATE);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// VCC ref
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ADMUX |= (0 &lt;&lt; REFS1) | (0 &lt;&lt; REFS0);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// RIGHT ADJUST
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ADCSRB |= (0 &lt;&lt; ADLAR);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// CHANNEL 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ADMUX |= (0 &lt;&lt; MUX5) | (0 &lt;&lt; MUX4) | (0 &lt;&lt; MUX3) | (0 &lt;&lt; MUX2) | (0 &lt;&lt; MUX1) | (1 &lt;&lt; MUX0);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// FREE RUNNING MODE
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ADCSRB |= (0 &lt;&lt; ADTS2) | (0 &lt;&lt; ADTS1) | (0 &lt;&lt; ADTS0);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// ENABLE ADC
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ADCSRA |= (1 &lt;&lt; ADEN);

&nbsp;&nbsp;&nbsp;&nbsp;// PORT A: INPUT
&nbsp;&nbsp;&nbsp;&nbsp;DDRA = 0x00;
&nbsp;&nbsp;&nbsp;&nbsp;PORTA = 0x00;

}

void pwminit (void) {
&nbsp;&nbsp;&nbsp;&nbsp;// disable PWM while configuring it
&nbsp;&nbsp;&nbsp;&nbsp;TCCR1A = 0;

&nbsp;&nbsp;&nbsp;&nbsp;// used for TOP, makes for 50 hz PWM = (8,000,000 / (8 * 50)) - 1
&nbsp;&nbsp;&nbsp;&nbsp;ICR1 = 19999;

&nbsp;&nbsp;&nbsp;&nbsp;// servo pins outputs
&nbsp;&nbsp;&nbsp;&nbsp;DDRA = _BV(PA5) | _BV(PA6);

&nbsp;&nbsp;&nbsp;&nbsp;// set up counter 1 (16 bit) to act as a dual channel PWM generator
&nbsp;&nbsp;&nbsp;&nbsp;// comparator mode = non-inverting, use ICR1 as TOP and have a prescale of 8.
&nbsp;&nbsp;&nbsp;&nbsp;TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11);
&nbsp;&nbsp;&nbsp;&nbsp;TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS11);
}

long map(long x, long in_min, long in_max, long out_min, long out_max)
{
&nbsp;&nbsp;return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

int main() {

&nbsp;&nbsp;adcinit();
&nbsp;&nbsp;pwminit();
&nbsp;&nbsp;&nbsp;&nbsp;sei();

&nbsp;&nbsp;&nbsp;&nbsp;// START A2D
&nbsp;&nbsp;&nbsp;&nbsp;ADCSRA |= (1 &lt;&lt; ADSC);

&nbsp;&nbsp;while(1) {
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;//700 to 2400
&nbsp;&nbsp;&nbsp;&nbsp;//but here we need only 50 degress
&nbsp;&nbsp;&nbsp;&nbsp;OCR1A = map(ADC, 0, 1023, 700, 1100);
&nbsp;&nbsp;&nbsp;&nbsp;ADMUX |= (1 &lt;&lt; MUX1);
&nbsp;&nbsp;&nbsp;&nbsp;ADMUX &amp;= ~(1 &lt;&lt; MUX0);
&nbsp;&nbsp;&nbsp;&nbsp;Delay_ms(2);
&nbsp;&nbsp;&nbsp;&nbsp;OCR1B = map(ADC, 0, 1023, 700, 1100);
&nbsp;&nbsp;&nbsp;&nbsp;ADMUX |= (1 &lt;&lt; MUX0);
&nbsp;&nbsp;&nbsp;&nbsp;ADMUX &amp;= ~(1 &lt;&lt; MUX1);
&nbsp;&nbsp;&nbsp;&nbsp;Delay_ms(2);
&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;return(0);
}
</pre></pre></p>
]]></content:encoded>
			<wfw:commentRss>http://www.workinprogress.ca/singing-birds/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>kohana 3.2 tutorial</title>
		<link>http://www.workinprogress.ca/kohana32/</link>
		<comments>http://www.workinprogress.ca/kohana32/#comments</comments>
		<pubDate>Sun, 04 Apr 2010 19:07:21 +0000</pubDate>
		<dc:creator>psc</dc:creator>
				<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.workinprogress.ca/?p=1370</guid>
		<description><![CDATA[Below you will find an article / tutorial on Kohana 3.2 &#8211; An elegant HMVC PHP5 framework that provides a rich set of components for building web applications. I am sharing a site template that use authentication &#038; internationalization. You can view the website (not much to see) and download it from github. Any pull [...]]]></description>
			<content:encoded><![CDATA[<p>Below you will find an article / tutorial on <a href="http://kohanaframework.org/" target="_blank">Kohana 3.2</a> &#8211; An elegant HMVC PHP5 framework that provides a rich set of components for building web applications.</p>
<p>I am sharing a site template that use authentication &#038; internationalization. You can view the website (not much to see) and download it from github. Any pull request will be more than welcome!</p>
<p><a href="http://www.workinprogress.ca/ko32example/site/"><img src="http://www.workinprogress.ca/wp-content/uploads/ko32example.png" alt="" title="ko32example" width="618" height="218" class="alignnone size-full wp-image-1493" /></a></p>
<p>Download via Github:<br />
<a href="https://github.com/patricksebastien/kohana-3.2-example"><img src="http://www.workinprogress.ca/wp-content/uploads/github.png" style="position: relative; top: 8px; padding-right: 6px;">https://github.com/patricksebastien/kohana-3.2-example</a></p>
<hr />
<span class="bigtitle">Topics</span></p>
<blockquote>
<ul>
<li><a href="#install">Install</a></li>
<li><a href="#template">Template</a></li>
<li><a href="#configuration">Configuration</a></li>
<li><a href="#validation">Validation</a></li>
<li><a href="#errorpage">Error page</a></li>
<li><a href="#authentication">Authentication</a></li>
<li><a href="#orm">ORM</a></li>
<li><a href="#database">Database</a></li>
<li><a href="#3rdparty">3rd party libraries</a></li>
<li><a href="#helper">Helper</a></li>
<li><a href="#tips">Tips</a></li>
<li><a href="#jquery">Jquery</a></li>
<li><a href="#bookmarks">Bookmarks</a></li>
<li><a href="#deploying">Deploying</a></li>
</ul>
</blockquote>
<hr />
<a name="install"></a><br />
<span class="bigtitle">Install</span></p>
<p>Using GIT:<br />
<a href="http://kohanaframework.org/3.2/guide/kohana/tutorials/git" target="_blank">http://kohanaframework.org/3.2/guide/kohana/tutorials/git</a><br />
or<br />
Download:<br />
<a href="http://kohanaframework.org/download" target="_blank">http://kohanaframework.org/download</a></p>
<hr />
<strong>Structure of folders:</strong><br />
<u>www/yoursite/<strong>site</strong>/index.php</u> &#038; <u>.htaccess</u> <em>-> and your assets (css, images, js)</em><br />
<u>www/yoursite/<strong>application</strong></u> <em>-> the very core of your site</em><br />
<u>www/yoursite/<strong>module</strong></u> &#038; <u><strong>system</strong></u> <em>-> core of kohana</em><br />
or:<br />
<u>www/<strong>kohana</strong>/version/system</u> &#038; <u>module</u> <em>-> multiple site using kohana</em><br />
or:<br />
everything in <u>www/yoursite/<strong>site</strong></u> (application, module, system, index.php, .htaccess, &#8230;)</p>
<hr />
<strong>Test:</strong><br />
127.0.0.1/<br />
If it&#8217;s greenish, then remove <u>install.php</u></p>
<hr />
<strong>index.php</strong><br />
Reflect this structure in <u>www/yoursite/site/index.php</u>:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$application</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'../application'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$modules</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'../modules'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$system</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'../system'</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<hr />
<strong>bootstrap.php</strong><br />
Modify <u>application/bootstrap.php</u></p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://www.php.net/date_default_timezone_set"><span style="color: #990000;">date_default_timezone_set</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'America/Montreal'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Set PRODUCTION vs DEVELOPMENT</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'KOHANA_ENV'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; Kohana<span style="color: #339933;">::</span><span style="color: #000088;">$environment</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/constant"><span style="color: #990000;">constant</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Kohana::'</span><span style="color: #339933;">.</span><a href="http://www.php.net/strtoupper"><span style="color: #990000;">strtoupper</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'KOHANA_ENV'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; Kohana<span style="color: #339933;">::</span><span style="color: #000088;">$environment</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'127.0.0.1'</span> ? Kohana<span style="color: #339933;">::</span><span style="color: #004000;">DEVELOPMENT</span> <span style="color: #339933;">:</span> Kohana<span style="color: #339933;">::</span><span style="color: #004000;">PRODUCTION</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Initialize Kohana</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">'base_url'</span> &nbsp; <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// or for example: /yoursite/site/mykoapp</span><br />
<span style="color: #0000ff;">'index_file'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// SEO (avoid index.php/mycontroller/action)</span><br />
<span style="color: #0000ff;">'profile'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#40;</span>Kohana<span style="color: #339933;">::</span><span style="color: #000088;">$environment</span> <span style="color: #339933;">!==</span> Kohana<span style="color: #339933;">::</span><span style="color: #004000;">PRODUCTION</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">//see how good you are</span><br />
<span style="color: #0000ff;">'caching'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#40;</span>Kohana<span style="color: #339933;">::</span><span style="color: #000088;">$environment</span> <span style="color: #339933;">===</span> Kohana<span style="color: #339933;">::</span><span style="color: #004000;">PRODUCTION</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
<span style="color: #0000ff;">'errors'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">//for custom 404, 500 FALSE for internal error handling</span></div></td></tr></tbody></table></div>
<p>Enable modules (for example):</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">'auth'</span> &nbsp; &nbsp; &nbsp; <span style="color: #339933;">=&gt;</span> MODPATH<span style="color: #339933;">.</span><span style="color: #0000ff;">'auth'</span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Basic authentication</span><br />
<span style="color: #0000ff;">'database'</span> &nbsp; <span style="color: #339933;">=&gt;</span> MODPATH<span style="color: #339933;">.</span><span style="color: #0000ff;">'database'</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #666666; font-style: italic;">// Database access</span><br />
<span style="color: #0000ff;">'orm'</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #339933;">=&gt;</span> MODPATH<span style="color: #339933;">.</span><span style="color: #0000ff;">'orm'</span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">// Object Relationship Mapping</span></div></td></tr></tbody></table></div>
<blockquote><p>Many modules are available:<br />
<a href="https://github.com/kolanos/kohana-universe" target="_blank">https://github.com/kolanos/kohana-universe</a><br />
<a href="http://kohana-modules.com/ " target="_blank">http://kohana-modules.com/ </a></p></blockquote>
<p>Set the routes (default controller will be login.php in this example)<br />
<a href="http://kohanaframework.org/3.2/guide/kohana/routing" target="_blank">http://kohanaframework.org/3.2/guide/kohana/routing</a></p>
<blockquote><p>The order of your routes are important!</p></blockquote>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Route<span style="color: #339933;">::</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'default'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'(&lt;controller&gt;(/&lt;action&gt;(/&lt;id&gt;)))'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">defaults</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'controller'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'login'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// application/classes/controller/login.php</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'action'</span> &nbsp; &nbsp; <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'index'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<hr />
<strong>.htaccess</strong><br />
Add this line at the very top of <u>.htaccess</u> (protect from sniffing directory)</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Options All <span style="color: #339933;">-</span>Indexes <span style="color: #339933;">-</span>Multiviews</div></td></tr></tbody></table></div>
<p>and modify (/ or for example: /yoursite/site/mykoapp)</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;"># Installation directory<br />
</span>RewriteBase <span style="color: #339933;">/</span></div></td></tr></tbody></table></div>
<p><a name="template">&nbsp;</a><br />
<span class="bigtitle">Template</span><br />
<a href="http://kerkness.ca/kowiki/doku.php?id=template-site:create_the_template" target="_blank">http://kerkness.ca/kowiki/doku.php?id=template-site:create_the_template</a> </p>
<p>Create the template controller (<u>classes/controller/template/website.php</u>) extending Controller_Template</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SYSPATH'</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">class</span> Controller_Template_Website <span style="color: #000000; font-weight: bold;">extends</span> Controller_Template<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$template</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'template/website'</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* The before() method is called before your controller action.<br />
&nbsp; &nbsp; &nbsp;* In our template controller we override this method so that we can<br />
&nbsp; &nbsp; &nbsp;* set up default values. These variables are then available to our<br />
&nbsp; &nbsp; &nbsp;* controllers if they need to be modified.<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> before<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; parent<span style="color: #339933;">::</span><span style="color: #004000;">before</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">auto_render</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Initialize empty values</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span> &nbsp; <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">styles</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">scripts</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* The after() method is called after your controller action.<br />
&nbsp; &nbsp; &nbsp;* In our template controller we override this method so that we can<br />
&nbsp; &nbsp; &nbsp;* make any last minute modifications to the template before anything<br />
&nbsp; &nbsp; &nbsp;* is rendered.<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> after<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">auto_render</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$styles</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'assets/css/website.css'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'screen, projection'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$scripts</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'http://code.jquery.com/jquery.min.js'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">styles</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array_merge"><span style="color: #990000;">array_merge</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">styles</span><span style="color: #339933;">,</span> <span style="color: #000088;">$styles</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">scripts</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array_merge"><span style="color: #990000;">array_merge</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">scripts</span><span style="color: #339933;">,</span> <span style="color: #000088;">$scripts</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; parent<span style="color: #339933;">::</span><span style="color: #004000;">after</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Create the controller (<u>classes/controller/login.php</u>) extending Controller_Template_Website (look at the second action for an example on how to use another template per action):</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">class</span> Controller_Login <span style="color: #000000; font-weight: bold;">extends</span> Controller_Template_Website <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> action_index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Log in'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content</span> <span style="color: #339933;">=</span> View<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'login'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// application/views/login.php</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// this action is using another template but using the same Controller_Template_Website</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> action_showinfooverlay<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'template/overlay'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; parent<span style="color: #339933;">::</span><span style="color: #004000;">before</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Log in'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content</span> <span style="color: #339933;">=</span> View<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'login'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// application/views/login.php</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Create the html template (<u>view/template/website.php</u>)</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;<br />
&nbsp; &nbsp; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt; <br />
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span>I18n<span style="color: #339933;">::</span><span style="color: #000088;">$lang</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; lang=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span>I18n<span style="color: #339933;">::</span><span style="color: #000088;">$lang</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt; <br />
&lt;head&gt; <br />
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html;charset=utf-8&quot; /&gt; <br />
&lt;meta name=&quot;language&quot; content=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> I18n<span style="color: #339933;">::</span><span style="color: #000088;">$lang</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt; <br />
&lt;title&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$title</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/title&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$styles</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$file</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$type</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> HTML<span style="color: #339933;">::</span><span style="color: #004000;">style</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'media'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$type</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> PHP_EOL <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$scripts</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> HTML<span style="color: #339933;">::</span><span style="color: #004000;">script</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> PHP_EOL <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;div id=&quot;wrapper&quot;&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$content</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</div></td></tr></tbody></table></div>
<p>Finally create your view content <u>application/views/login.php</u></p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> Form<span style="color: #339933;">::</span><span style="color: #004000;">open</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&lt;dl&gt;<br />
&nbsp; &nbsp; &lt;dt&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> Form<span style="color: #339933;">::</span><span style="color: #004000;">label</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'User'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/dt&gt;<br />
&nbsp; &nbsp; &lt;dd&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> Form<span style="color: #339933;">::</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/dd&gt;<br />
&nbsp; &nbsp; &lt;dt&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> Form<span style="color: #339933;">::</span><span style="color: #004000;">label</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Pwd'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/dt&gt;<br />
&nbsp; &nbsp; &lt;dd&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> Form<span style="color: #339933;">::</span><span style="color: #004000;">password</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/dd&gt;<br />
&lt;/dl&gt;<br />
&lt;p&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> Form<span style="color: #339933;">::</span><span style="color: #004000;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Log in'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/p&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> Form<span style="color: #339933;">::</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>At this point you can point your browser to see the login page:<br />
<a href="http://localhost/" target="_blank">http://localhost/</a>  <em>-> depending on base_url and .htaccess (could be in a sub-folder)</em><br />
<a href="http://localhost/login" target="_blank">http://localhost/login</a> <em>-> not defined login as the default controller in <u>bootstrap.php</u></em></p>
<blockquote><p>Someone on #kohana (irc / freenode) made a suggestion of using view classes instead of template controller. Here&#8217;s two solutions: <a href="https://github.com/zombor/kostache" target="_blank">https://github.com/zombor/kostache</a> &#038; <a href="https://github.com/beautiful/view" target="_blank">https://github.com/beautiful/view</a></p></blockquote>
<p><a name="configuration">&nbsp;</a><br />
<span class="bigtitle">Configure</span><br />
<strong>Database</strong><br />
Copy <u>modules/database/config/database.php</u> to <u>application/config/database.php</u></p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">'default'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><br />
<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'type'</span> &nbsp; &nbsp; &nbsp; <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'mysql'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'connection'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'hostname'</span> &nbsp; <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'database'</span> &nbsp; <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'yourdb'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'username'</span> &nbsp; <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'user'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'password'</span> &nbsp; <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'pwd'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'persistent'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'table_prefix'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'charset'</span> &nbsp; &nbsp; &nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'utf8'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'caching'</span> &nbsp; &nbsp; &nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'profiling'</span> &nbsp; &nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// if you use profiling turn this on (to see querys)</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span></div></td></tr></tbody></table></div>
<hr />
<strong>Cookie</strong><br />
in <u>application/bootstrap.php</u></p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009933; font-style: italic;">/**<br />
&nbsp;* Cookie<br />
&nbsp;*/</span><br />
<span style="color: #666666; font-style: italic;">// Set the magic salt to add to a cookie</span><br />
Cookie<span style="color: #339933;">::</span><span style="color: #000088;">$salt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'fjsdijeihrewhbfsugfuyegwufewgwb'</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// Set the number of seconds before a cookie expires</span><br />
Cookie<span style="color: #339933;">::</span><span style="color: #000088;">$expiration</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/date"><span style="color: #990000;">DATE</span></a><span style="color: #339933;">::</span><span style="color: #004000;">WEEK</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// by default until the browser close</span><br />
<span style="color: #666666; font-style: italic;">// Restrict the path that the cookie is available to</span><br />
<span style="color: #666666; font-style: italic;">//Cookie::$path = '/';</span><br />
<span style="color: #666666; font-style: italic;">// Restrict the domain that the cookie is available to</span><br />
<span style="color: #666666; font-style: italic;">//Cookie::$domain = 'www.mydomain.com';</span><br />
<span style="color: #666666; font-style: italic;">// Only transmit cookies over secure connections</span><br />
<span style="color: #666666; font-style: italic;">//Cookie::$secure = TRUE;</span><br />
<span style="color: #666666; font-style: italic;">// Only transmit cookies over HTTP, disabling Javascript access</span><br />
<span style="color: #666666; font-style: italic;">//Cookie::$httponly = TRUE;</span></div></td></tr></tbody></table></div>
<hr />
<strong>Session</strong> (stored in database)<br />
<a href="http://kohanaframework.org/3.2/guide/kohana/sessions" target="_blank">http://kohanaframework.org/3.2/guide/kohana/sessions</a><br />
in <u>application/bootstrap.php</u> add the default session handler:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Session<span style="color: #339933;">::</span><span style="color: #000088;">$default</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'database'</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Copy <u>system/config/encrypt.php</u> to <u>application/config/encrypt.php</u></p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">return</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">'default'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'key'</span> &nbsp; <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'fjdsjkfdskjfurew'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'cipher'</span> <span style="color: #339933;">=&gt;</span> MCRYPT_RIJNDAEL_128<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'mode'</span> &nbsp; <span style="color: #339933;">=&gt;</span> MCRYPT_MODE_NOFB<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
<br />
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Create a table if you want to use database session</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CREATE TABLE &nbsp;`sessions` <span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; `<a href="http://www.php.net/session_id"><span style="color: #990000;">session_id</span></a>` VARCHAR<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">24</span><span style="color: #009900;">&#41;</span> NOT <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; `last_active` INT UNSIGNED NOT <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; `contents` TEXT NOT <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; PRIMARY <a href="http://www.php.net/key"><span style="color: #990000;">KEY</span></a> <span style="color: #009900;">&#40;</span>`<a href="http://www.php.net/session_id"><span style="color: #990000;">session_id</span></a>`<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; INDEX <span style="color: #009900;">&#40;</span>`last_active`<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span> ENGINE <span style="color: #339933;">=</span> MYISAM<span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Copy <u>system/config/session.php</u> to <u>application/config/session.php</u></p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">return</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'database'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'session'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'encrypted'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// need a key in config/encrypt.php</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'lifetime'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/date"><span style="color: #990000;">DATE</span></a><span style="color: #339933;">::</span><span style="color: #004000;">HOUR</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// 0 = expire when the browser close</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'group'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'default'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'table'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'sessions'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'columns'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'session_id'</span> &nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'session_id'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'last_active'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'last_active'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'contents'</span> &nbsp; &nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'contents'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'gc'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">500</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Use it in your controller:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Session<span style="color: #339933;">::</span><span style="color: #004000;">instance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'key'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
Session<span style="color: #339933;">::</span><span style="color: #004000;">instance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'key'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<hr />
<strong>yoursite</strong><br />
Create a file in <u>application/config/yoursite.php</u></p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SYSPATH'</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct access allowed.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">return</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'myconfig1'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'fjdsjkfdskjfurew'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'playlists'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><br />
&nbsp; &nbsp; <span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">1478363</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">10171</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">22857234</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">10171</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">386</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">10171</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">722</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">10171</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">893</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">10171</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">237</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">10171</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <br />
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Then you can call a config like this:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$playlists</span> <span style="color: #339933;">=</span> Kohana<span style="color: #339933;">::</span><span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'yoursite.playlists'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
Kohana<span style="color: #339933;">::</span><span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'yoursite.myconfig1 '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<hr />
<strong>Message</strong><br />
(might be better to use I18N directly)</p>
<p>Create a file in <u>application/message/yoursite.php</u> for you project</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SYSPATH'</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">return</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'permission'</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'You don\'t have the permission'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'wrong'</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Wrong username or password'</span><span style="color: #339933;">,</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Then you can use it like this:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Kohana<span style="color: #339933;">::</span><span style="color: #004000;">message</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'yoursite'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'permission'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<hr />
<strong>Translation</strong><br />
<a href="http://blog.mixu.net/2010/11/11/kohana-3-i18n-tutorial/" target="_blank">http://blog.mixu.net/2010/11/11/kohana-3-i18n-tutorial/</a></p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Dear :firstname, your username is: :user'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':firstname'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'gfdgfdg'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">':user'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'gfdgfd'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p><a name="validation">&nbsp;</a><br />
<span class="bigtitle">Validation</span><br />
<a href="http://kohanaframework.org/3.2/guide/kohana/security/validation" target="_blank">http://kohanaframework.org/3.2/guide/kohana/security/validation</a><br />
Copy <u>system/messages/validation</u> to <u>application/message/validation.php</u> if you want to change the error message</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// Validate a form ($_POST)</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> Valid<span style="color: #339933;">::</span><span style="color: #004000;">not_empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Validate the login form</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$post</span> <span style="color: #339933;">=</span> Validation<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">rule</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'not_empty'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">rule</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'regex'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':value'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/^[a-z_.]++$/iD'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">rule</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'not_empty'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">rule</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'min_length'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':value'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// If the form is valid and the username and password matches</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">check</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Validated'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Using a callback for custom validation &#038; error message</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// form post handling</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> Valid<span style="color: #339933;">::</span><span style="color: #004000;">not_empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// validate</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$post</span> <span style="color: #339933;">=</span> Validation<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">rule</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'alpha_numeric'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">rule</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'pwdneusr'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':validation'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">':field'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">check</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// CALLBACK</span><br />
<span style="color: #666666; font-style: italic;">// validation rule: password != username</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> pwdneusr<span style="color: #009900;">&#40;</span><span style="color: #000088;">$validation</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$validation</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$validation</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'pwdneusr'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p><a name="errorpage">&nbsp;</a><br />
<span class="bigtitle">Error page</span></p>
<p><a href="http://kohanaframework.org/3.2/guide/kohana/tutorials/error-pages" target="_blank">http://kohanaframework.org/3.2/guide/kohana/tutorials/error-pages</a> </p>
<p>Create the views<br />
<u>views/error/404.php</u> / <u>500.php</u> etc&#8230;</p>
<p>Extend the exception handler of Kohana<br />
<u>classes/kohana/exception.php</u></p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SYSPATH'</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">class</span> Kohana_Exception <span style="color: #000000; font-weight: bold;">extends</span> Kohana_Kohana_Exception <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> handler<span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>Kohana<span style="color: #339933;">::</span><span style="color: #004000;">DEVELOPMENT</span> <span style="color: #339933;">===</span> Kohana<span style="color: #339933;">::</span><span style="color: #000088;">$environment</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parent<span style="color: #339933;">::</span><span style="color: #004000;">handler</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Kohana<span style="color: #339933;">::</span><span style="color: #000088;">$log</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/log"><span style="color: #990000;">Log</span></a><span style="color: #339933;">::</span><span style="color: #004000;">ERROR</span><span style="color: #339933;">,</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">text</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$attributes</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'controller'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'error'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'action'</span> &nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">500</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'message'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/rawurlencode"><span style="color: #990000;">rawurlencode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span> instanceof HTTP_Exception<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$attributes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Error sub-request.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> Request<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span>Route<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">uri</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attributes</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">send_headers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">body</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Clean the output buffer if one exists</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/ob_get_level"><span style="color: #990000;">ob_get_level</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> and <a href="http://www.php.net/ob_clean"><span style="color: #990000;">ob_clean</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Display the exception text</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">text</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Exit with an error status</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/exit"><span style="color: #990000;">exit</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Create the controller:<br />
<u>classes/controller/error.php</u></p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SYSPATH'</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
<span style="color: #000000; font-weight: bold;">class</span> Controller_Error <span style="color: #000000; font-weight: bold;">extends</span> Controller_Template_Nobrand <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> before<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; parent<span style="color: #339933;">::</span><span style="color: #004000;">before</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Internal request only!</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>Request<span style="color: #339933;">::</span><span style="color: #000088;">$initial</span> <span style="color: #339933;">!==</span> Request<span style="color: #339933;">::</span><span style="color: #000088;">$current</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/rawurldecode"><span style="color: #990000;">rawurldecode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">param</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">message</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$message</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">404</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">status</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> action_404<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'404 Not Found'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content</span> <span style="color: #339933;">=</span> View<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error/404'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> action_500<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Internal Server Error'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content</span> <span style="color: #339933;">=</span> View<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error/500'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> action_503<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Maintenance Mode'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content</span> <span style="color: #339933;">=</span> View<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error/503'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Edit <u>application/bootstrap.php</u> to add the route:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Route<span style="color: #339933;">::</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'error/&lt;action&gt;(/&lt;message&gt;)'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'[0-9]++'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'message'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'.+'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">defaults</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'controller'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'error'</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p><a name="authentication">&nbsp;</a><br />
<span class="bigtitle">Authentication</span><br />
Copy <u>modules/auth/config/auth.php</u> to <u>application/config/auth.php</u></p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">return</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'driver'</span> &nbsp; &nbsp; &nbsp; <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'orm'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'hash_method'</span> &nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'sha256'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'hash_key'</span> &nbsp; &nbsp; <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'wigbble'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'lifetime'</span> &nbsp; &nbsp; <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/date"><span style="color: #990000;">Date</span></a><span style="color: #339933;">::</span><span style="color: #004000;">HOUR</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'session_key'</span> &nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'auth_user'</span><span style="color: #339933;">,</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Schema for mysql / postgresql located:<br />
<u>modules/orm/auth-schema-mysql.sql</u></p>
<p>Change the rules if you don&#8217;t want to required an email (you will also need to remove the index in mysql: uniq_email &#8211; BTREE)<br />
Copy <u>modules/orm/classes/model/auth/user.php</u> to <u>application/classes/model/auth/user.php</u> and change the public function rules() to your needs</p>
<p>It&#8217;s a good idea to add a new role for your normal user, that way you can list them easily:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> ORM<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'role'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'participant'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">users</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find_all</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Create <u>application/messages/models/user.php</u></p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SYSPATH'</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">return</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'username.unique'</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Username must be unique'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'email.unique'</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Email must be unique'</span><span style="color: #339933;">,</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>If you want to use the remember feature:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$remember</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'remember'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
Auth<span style="color: #339933;">::</span><span style="color: #004000;">instance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">login</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$post</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$remember</span><span style="color: #009900;">&#41;</span></div></td></tr></tbody></table></div>
<p>then you need to be sure to have a cookie salt in <u>application/bootstrap.php</u></p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009933; font-style: italic;">/**<br />
* Cookie salt for remember user info<br />
*/</span><br />
Cookie<span style="color: #339933;">::</span><span style="color: #000088;">$salt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'fdsh-tretgd-re-gfds-gt-erg-fdg-'</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Some useful stuff:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// Add an administrator (in a temporary controller)</span><br />
<span style="color: #000088;">$model</span> <span style="color: #339933;">=</span> ORM<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">values</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'admin'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'password'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'admin'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'password_confirm'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'admin'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'email'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'your@email.com'</span><span style="color: #339933;">,</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// remember to add the login role AND the admin role</span><br />
<span style="color: #666666; font-style: italic;">// add a role; add() executes the query immediately</span><br />
<span style="color: #000088;">$model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'roles'</span><span style="color: #339933;">,</span> ORM<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'role'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'='</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'login'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'roles'</span><span style="color: #339933;">,</span> ORM<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'role'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'='</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'admin'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// If this user doesn't have the admin role, and is not trying to login, redirect to login</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> before<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; parent<span style="color: #339933;">::</span><span style="color: #004000;">before</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> Auth<span style="color: #339933;">::</span><span style="color: #004000;">instance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">logged_in</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin'</span><span style="color: #009900;">&#41;</span> AND Request<span style="color: #339933;">::</span><a href="http://www.php.net/current"><span style="color: #990000;">current</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">uri</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #0000ff;">'manage'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/manage'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// Administrator already logged in, redirect to dashboard</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>Auth<span style="color: #339933;">::</span><span style="color: #004000;">instance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">logged_in</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'manage/dashboard'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// Log the user</span><br />
Auth<span style="color: #339933;">::</span><span style="color: #004000;">instance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">login</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$post</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// Check if the user have the admin permission</span><br />
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>Auth<span style="color: #339933;">::</span><span style="color: #004000;">instance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">logged_in</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// Log user out</span><br />
Auth<span style="color: #339933;">::</span><span style="color: #004000;">instance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">logout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// check if email or username (automagic) is already taken</span><br />
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>ORM<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">unique_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;FOUND&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p><a name="orm">&nbsp;</a><br />
<span class="bigtitle">ORM</span><br />
<a href="http://kohanaframework.org/3.2/guide/orm/" target="_blank">http://kohanaframework.org/3.2/guide/orm/</a><br />
<a href="http://karlsheen.com/kohana/kohana-3-orm-tutorial-and-samples/" target="_blank">http://karlsheen.com/kohana/kohana-3-orm-tutorial-and-samples/</a><br />
<a href="http://kohanaframework.blogspot.com/2010/12/kohana-3-orm-simple-example.html" target="_blank">http://kohanaframework.blogspot.com/2010/12/kohana-3-orm-simple-example.html</a><br />
<a href="http://www.geekgumbo.com/2011/05/24/kohana-3-orm-a-working-example/" target="_blank">http://www.geekgumbo.com/2011/05/24/kohana-3-orm-a-working-example/</a><br />
<a href="http://kohanaframework.org/3.2/guide/api/ORM" target="_blank">http://kohanaframework.org/3.2/guide/api/ORM</a></p>
<p>ORM is included with the Kohana 3.x install but needs to be enabled before you can use it. In your <u>application/bootstrap.php</u> file modify the call to Kohana::modules and include the ORM modules:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">'orm'</span> <span style="color: #339933;">=&gt;</span> MODPATH<span style="color: #339933;">.</span><span style="color: #0000ff;">'orm'</span><span style="color: #339933;">,</span></div></td></tr></tbody></table></div>
<blockquote><p>The table name must be in plural;<br />
The table must have an id with auto increment (required);<br />
You must create a Model that extends ORM class (this one not in plural)</p></blockquote>
<p><strong>1)</strong><br />
Create a table with a &#8220;s&#8221; as the end:</p>
<blockquote><p>tracking -> trackings<br />
category -> categories</p></blockquote>
<p><strong>2)</strong><br />
Create a model (<u>application/classes/model</u>) without the &#8220;s&#8221;</p>
<blockquote><p>tracking.php<br />
category.php</p></blockquote>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SYSPATH'</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct access allowed.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">class</span> Model_Tracking <span style="color: #000000; font-weight: bold;">extends</span> ORM<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">...</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SYSPATH'</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct access allowed.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">class</span> Model_Category <span style="color: #000000; font-weight: bold;">extends</span> ORM<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">...</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>3)</strong><br />
Establish your relation (one-to-one, one-to-many etc&#8230;)</p>
<p><strong>4)</strong><br />
Use your model / ORM</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">try<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$tracking</span> <span style="color: #339933;">=</span> ORM<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tracking'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$tracking</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user_id</span> <span style="color: #339933;">=</span> Auth<span style="color: #339933;">::</span><span style="color: #004000;">instance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_user</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$tracking</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">session_id</span> <span style="color: #339933;">=</span> Session<span style="color: #339933;">::</span><span style="color: #004000;">instance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$tracking</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">' fdsfdsf '</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tracking</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;save&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;for some reason, there's an error&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
catch <span style="color: #009900;">&#40;</span>ORM_Validation_Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;error&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/var_dump"><span style="color: #990000;">var_dump</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errors</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Some useful stuff:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> ORM<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count_all</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">last_query</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$playlists</span> <span style="color: #339933;">=</span> ORM<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'playlist'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'week_id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'='</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find_all</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$playlists</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$playlist</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$playlist</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Last ID from ->save();</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$myormmodel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$myormmodel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<hr />
<strong>ORM Validation</strong><br />
<a href="http://kohanaframework.org/3.2/guide/orm/examples/validation" target="_blank">http://kohanaframework.org/3.2/guide/orm/examples/validation</a><br />
<a href="http://kohanaframework.org/3.2/guide/kohana/security/validation" target="_blank">http://kohanaframework.org/3.2/guide/kohana/security/validation</a></p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SYSPATH'</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct access allowed.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">class</span> Model_Member <span style="color: #000000; font-weight: bold;">extends</span> ORM <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> rules<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'not_empty'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'min_length'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':value'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'max_length'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':value'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">32</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'username_available'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'password'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'not_empty'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> filters<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'password'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'hash_password'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> username_available<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// There are simpler ways to do this, but I will use ORM for the sake of the example</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> ORM<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'member'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loaded</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> hash_password<span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Do something to hash the password</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p><a name="database">&nbsp;</a><br />
<span class="bigtitle">Database:</span><br />
<a href="http://kohanaframework.org/3.2/guide/database/" target="_blank">http://kohanaframework.org/3.2/guide/database/ </a><br />
<a href="http://kohanaframework.org/3.2/guide/api/Database" target="_blank">http://kohanaframework.org/3.2/guide/api/Database</a> </p>
<p>There&#8217;s 2 ways to query a database: prepared (normal SQL) and query builder (dynamic)</p>
<p>Prepared:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> DB<span style="color: #339933;">::</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span>Database<span style="color: #339933;">::</span><span style="color: #004000;">SELECT</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'SELECT * FROM users WHERE username = :user AND status = :status'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
 <br />
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">parameters</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
    <span style="color: #0000ff;">':user'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'john'</span><span style="color: #339933;">,</span><br />
    <span style="color: #0000ff;">':status'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'active'</span><span style="color: #339933;">,</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Query builder:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> DB<span style="color: #339933;">::</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'users'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'='</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'john'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> DB<span style="color: #339933;">::</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">distinct</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'posts'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> DB<span style="color: #339933;">::</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span><span style="color: #009900;">&#40;</span>`posts`<span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">limit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">offset</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
…</div></td></tr></tbody></table></div>
<p>Results:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> DB<span style="color: #339933;">::</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'users'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'verified'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'='</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
    <span style="color: #666666; font-style: italic;">// Send reminder email to $user['email']</span><br />
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; needs to verify his/her account<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> DB<span style="color: #339933;">::</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'users'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'verified'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'='</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">as_object</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
    <span style="color: #666666; font-style: italic;">// Send reminder email to $user-&gt;email</span><br />
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">email</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; needs to verify his/her account<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Only get 1 result:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$total_users</span> <span style="color: #339933;">=</span> DB<span style="color: #339933;">::</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'COUNT(&quot;username&quot;)'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'total_users'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'users'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'total_users'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// Get the total number of records in the &quot;users&quot; table</span><br />
<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> Database<span style="color: #339933;">::</span><span style="color: #004000;">instance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count_records</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'testi'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p><a name="3rdparty">&nbsp;</a><br />
<span class="bigtitle">3rd party libraries</span><br />
The convention is to place 3rd party files in <u>application/vendor</u>. For instance, if you had an installation of Doctrine, you would place it in <u>application/vendor/doctrine</u>.</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">require</span> Kohana<span style="color: #339933;">::</span><span style="color: #004000;">find_file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'vendor'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Swift-4.0.5/lib/swift_required'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$transport</span> <span style="color: #339933;">=</span> Swift_SmtpTransport<span style="color: #339933;">::</span><span style="color: #004000;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">...</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// This is autoloaded for me by Swiftmailer</span></div></td></tr></tbody></table></div>
<p>PHPExcel &#8211; create PDF, CSV, Excel:<br />
<u>application/vendor/phpexcel/PHPExcel.php</u> &#038; <u>PHPExcel</u><br />
then in your controller:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">require</span> Kohana<span style="color: #339933;">::</span><span style="color: #004000;">find_file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'vendor'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'phpexcel/PHPExcel'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$objPHPExcel</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PHPExcel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Email &#8211; you can use this module:<br />
<a href="https://github.com/Luwe/Kohana-Email" target="_blank">https://github.com/Luwe/Kohana-Email</a><br />
or directly use swiftmailer:<br />
<a href="http://swiftmailer.org/" target="_blank">http://swiftmailer.org/</a></p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">require</span> Kohana<span style="color: #339933;">::</span><span style="color: #004000;">find_file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'vendor'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'swift/swift_required'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">//Create the Transport</span><br />
<span style="color: #000088;">$transport</span> <span style="color: #339933;">=</span> Swift_SmtpTransport<span style="color: #339933;">::</span><span style="color: #004000;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">//Create the Mailer using your created Transport</span><br />
<span style="color: #000088;">$mailer</span> <span style="color: #339933;">=</span> Swift_Mailer<span style="color: #339933;">::</span><span style="color: #004000;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$transport</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">//Create a message</span><br />
<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> Swift_Message<span style="color: #339933;">::</span><span style="color: #004000;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Email'</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFrom</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'from@email.net'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'From'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTo</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'to@email.net'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #339933;">-&gt;</span><span style="color: #004000;">setBody</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'An email'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">//Send the message</span><br />
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$mailer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">send</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p><a name="helper">&nbsp;</a><br />
<span class="bigtitle">Helper</span><br />
<a href="http://kohanaframework.org/3.2/guide/api/Arr" target="_blank">http://kohanaframework.org/3.2/guide/api/Arr</a><br />
If you want to add some custom helper (generally used statically) or library (instantiated / object), for example: <u>application/classes/participants.php</u></p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SYSPATH'</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">class</span> Participant <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; static <span style="color: #000000; font-weight: bold;">function</span> currentweek<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>in your controller:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$weektodisplay</span> <span style="color: #339933;">=</span> Participant<span style="color: #339933;">::</span><span style="color: #004000;">currentweek</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p><a name="tips">&nbsp;</a><br />
<span class="bigtitle">Tips</span><br />
To get the params in a controller (depending on your routes in <u>application/bootstrap.php</u>)</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">param</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#41;</span></div></td></tr></tbody></table></div>
<p>Debug:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">echo</span> Debug<span style="color: #339933;">::</span><span style="color: #004000;">vars</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>To get the current controller:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">echo</span> Request<span style="color: #339933;">::</span><a href="http://www.php.net/current"><span style="color: #990000;">current</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">uri</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>To point at the right directory use:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> URL<span style="color: #339933;">::</span><span style="color: #004000;">base</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>To get a custom column from users (auth):</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">echo</span> Auth<span style="color: #339933;">::</span><span style="color: #004000;">instance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_user</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">week</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Date:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://www.php.net/date"><span style="color: #990000;">Date</span></a><span style="color: #339933;">::</span><span style="color: #004000;">formatted_time</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'now'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'m-d-Y'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">//constant Date::WEEK Date::YEAR</span></div></td></tr></tbody></table></div>
<p>Way to use the model and the post for edition in form:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// Received the POST</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> Valid<span style="color: #339933;">::</span><span style="color: #004000;">not_empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// keep but not saved</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$participant</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">values</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>To redirect use:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'manage/dashboard'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>To make a link use:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> HTML<span style="color: #339933;">::</span><span style="color: #004000;">anchor</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'playlist'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Playlist'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'style'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'color: #FFF'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>Function inside controller:<br />
inside action_x():</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://www.php.net/array_walk"><span style="color: #990000;">array_walk</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trackings</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'_replaceplaylistendtime'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>outside action_x():</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">static <span style="color: #000000; font-weight: bold;">function</span> _replaceplaylistendtime<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">...</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p><a name="jquery">&nbsp;</a><br />
<span class="bigtitle">Jquery</span><br />
Use the latest minified version on google server:<br />
<a href="http://code.jquery.com/jquery.min.js" target="_blank">http://code.jquery.com/jquery.min.js</a></p>
<p>User interface:<br />
<a href="http://ninjaui.com/" target="_blank">http://ninjaui.com/</a><br />
<a href="http://jqueryui.com/" target="_blank">http://jqueryui.com/</a><br />
<a href="http://flowplayer.org/tools/index.html" target="_blank">http://flowplayer.org/tools/index.html</a> </p>
<p>Ajax:<br />
In your &#8220;ajax&#8221; controller / action</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">is_ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/json_decode"><span style="color: #990000;">json_decode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'refresh'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">auto_render</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <a href="http://www.php.net/json_encode"><span style="color: #990000;">json_encode</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'result'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>In your jquery:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$.ajax({<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: &quot;POST&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url: &quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> URL<span style="color: #339933;">::</span><span style="color: #004000;">base</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>home/refresh&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data: &quot;refresh=1&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; async: true,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dataType: &quot;json&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; success: function(resultArray, textStatus, XMLHttpRequest)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var result = parseInt(resultArray['result']);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(result);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; error: function(request, textStatus, errorThrown)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert('error refreshing the session');<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
});</div></td></tr></tbody></table></div>
<p><a name="bookmarks">&nbsp;</a><br />
<span class="bigtitle">Bookmarks</span><br />
<a href="http://kohanaframework.org/3.2/guide/kohana/tutorials/" target="_blank">http://kohanaframework.org/3.2/guide/kohana/tutorials/</a><br />
<a href="http://kohanaframework.org/3.2/guide/api" target="_blank">http://kohanaframework.org/3.2/guide/api</a> or <a href="http://kohana.nerdblog.pl/api/" target="_blank">http://kohana.nerdblog.pl/api/</a> </p>
<p><a name="deploying">&nbsp;</a><br />
<span class="bigtitle">Deploying:</span><br />
See this for more information about deploying Kohana application<br />
<a href="http://nerdblog.pl/2011/09/05/deploying-kohana-3-2-application-in-production/" target="_blank">http://nerdblog.pl/2011/09/05/deploying-kohana-3-2-application-in-production/</a> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.workinprogress.ca/kohana32/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>biscuit box computer</title>
		<link>http://www.workinprogress.ca/biscuit-box-computer/</link>
		<comments>http://www.workinprogress.ca/biscuit-box-computer/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 23:06:04 +0000</pubDate>
		<dc:creator>psc</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://www.workinprogress.ca/?p=674</guid>
		<description><![CDATA[i am sure there&#8217;s plenty of projects like this one. the idea is to get a &#8220;cheap&#8221; and &#8220;small&#8221; full featured linux box. a good keyword to start with: itx motherboard cpu combo. this one have hdmi 1080p, wifi, dual-core 1.6 ghz. i paid 147$ used. got also 1 gig of used ram for 20$. [...]]]></description>
			<content:encoded><![CDATA[<p>i am sure there&#8217;s plenty of projects like this one. the idea is to get a &#8220;cheap&#8221; and &#8220;small&#8221; full featured linux box. a good keyword to start with: itx motherboard cpu combo. this one have hdmi 1080p, wifi, dual-core 1.6 ghz. i paid 147$ used. got also 1 gig of used ram for 20$. total of 167$ CAD. weight is 0.8 kg for the box and 0.3 kg for the supply. Just 18W at idle, and 23W full load (someone measured it with a Kill-a-watt device). the power supply is 90W. for the storage, i went with a laptop hard-drive (it&#8217;s smaller). i paid 100$ for a 500 gig, 7200 rpm, sata.</p>
<p>all this information will be outdated, now.</p>

<a href='http://www.workinprogress.ca/biscuit-box-computer/p4020066/' title='P4020066'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/P4020066-150x150.jpg" class="attachment-thumbnail" alt="P4020066" title="P4020066" /></a>
<a href='http://www.workinprogress.ca/biscuit-box-computer/p4020069/' title='itx motherboard cpu combo with the external supply'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/P4020069-150x150.jpg" class="attachment-thumbnail" alt="itx motherboard cpu combo with the external supply" title="itx motherboard cpu combo with the external supply" /></a>
<a href='http://www.workinprogress.ca/biscuit-box-computer/p4020072/' title='P4020072'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/P4020072-150x150.jpg" class="attachment-thumbnail" alt="P4020072" title="P4020072" /></a>
<a href='http://www.workinprogress.ca/biscuit-box-computer/p4020073/' title='P4020073'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/P4020073-150x150.jpg" class="attachment-thumbnail" alt="P4020073" title="P4020073" /></a>
<a href='http://www.workinprogress.ca/biscuit-box-computer/p4020074/' title='P4020074'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/P4020074-150x150.jpg" class="attachment-thumbnail" alt="P4020074" title="P4020074" /></a>
<a href='http://www.workinprogress.ca/biscuit-box-computer/p4300098/' title='laptop hard-drive fixed on top'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/P4300098-150x150.jpg" class="attachment-thumbnail" alt="laptop hard-drive fixed on top" title="laptop hard-drive fixed on top" /></a>

<p>running a realtime kernel with enlightenment and blender:</p>
<p><object width="400" height="320"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=11384664&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=11384664&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="320"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.workinprogress.ca/biscuit-box-computer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

