<?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>Yii Framework</title>
	<atom:link href="http://tariffstreet.com/yii/feed/" rel="self" type="application/rss+xml" />
	<link>http://tariffstreet.com/yii</link>
	<description>Tariff Street Ltd.</description>
	<lastBuildDate>Fri, 05 Apr 2013 10:31:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Removing a file from git versioning</title>
		<link>http://tariffstreet.com/yii/2013/02/removing-a-file-from-git-versioning/</link>
		<comments>http://tariffstreet.com/yii/2013/02/removing-a-file-from-git-versioning/#comments</comments>
		<pubDate>Mon, 18 Feb 2013 14:31:56 +0000</pubDate>
		<dc:creator>Harry Bailey</dc:creator>
				<category><![CDATA[Code Examples]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://tariffstreet.com/yii/?p=112</guid>
		<description><![CDATA[There are two steps to taking a file back out of any repo that you manage while not deleting it. 1) Add the file to your .gitignore file. If you don&#8217;t have one already, still a new file called .gitignore &#8230; <a href="http://tariffstreet.com/yii/2013/02/removing-a-file-from-git-versioning/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There are two steps to taking a file back out of any repo that you manage while not deleting it.</p>
<p>1) Add the file to your .gitignore file.</p>
<p>If you don&#8217;t have one already, still a new file called .gitignore into the root of your repo.</p>
<p>Into your gitignote file add the file you want to remove:</p>
<pre>path/to/file.txt</pre>
<p>2) Tell git to stop looking at the file which was already in the version control system.</p>
<pre>git rm --cached path/to/file.text</pre>
<p>And you&#8217;re there. File still exists, but git will stop looking at it for changes.</p>
]]></content:encoded>
			<wfw:commentRss>http://tariffstreet.com/yii/2013/02/removing-a-file-from-git-versioning/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Global Unique IDs or GUIDs</title>
		<link>http://tariffstreet.com/yii/2012/06/mysql-global-unique-ids-or-guids/</link>
		<comments>http://tariffstreet.com/yii/2012/06/mysql-global-unique-ids-or-guids/#comments</comments>
		<pubDate>Thu, 21 Jun 2012 10:31:26 +0000</pubDate>
		<dc:creator>Harry Bailey</dc:creator>
				<category><![CDATA[Theory and Thoughts]]></category>

		<guid isPermaLink="false">http://tariffstreet.com/yii/?p=100</guid>
		<description><![CDATA[99% of websites use databases which contain a primary key, auto incrementing id column. It&#8217;s used to link any related tables together and allows very fast select of one or more specified rows. When you are linking tables in a &#8230; <a href="http://tariffstreet.com/yii/2012/06/mysql-global-unique-ids-or-guids/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>99% of websites use databases which contain a primary key, auto incrementing id column.</p>
<p>It&#8217;s used to link any related tables together and allows very fast select of one or more specified rows.</p>
<p>When you are linking tables in a standard way ids work just fine and there is no need to consider global unique ids. So when should you consider them at all?</p>
<p>MySQL can&#8217;t cope with what are called Polymorphic Associations. That is, a second table is joined in a query based on the value of a column in the first table.</p>
<p>Let me give you an example. I want to link an address table to the people table, office table and factory table. My options would be to include a column for each into the address table, and only populate one for each row or include a type column and then the id of the thing that it is related to. Neither are great, especially when you have a new thing that an address could be related to. You need to keep adding columns or do a separate select for each type of thing you want the addresses for.</p>
<p>The alternative to all this chaos is the global unique id, or guid.</p>
<p>If everything in the relevant tables of your database had their own unique id, you could join person, office and factory onto your people table based on a single column &#8211; for argument&#8217;s sake let&#8217;s call it owner_id &#8211; and you&#8217;ll get everything you want back in a single query.</p>
<p>If you set up your site to do this from the start it&#8217;s pretty painless.</p>
<p>You&#8217;ll need an additional table called something like guid which will have a single column id and only be used to supply unique ids to use in other tables.</p>
<p>All other tables will need the auto increment on the id column removing.</p>
<p>When you want to insert a new office, factory or person you first insert a new line into the guid table and then use that new guid as the id for your new row.</p>
<p>I&#8217;ll write about how to use guids in Yii in another article soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://tariffstreet.com/yii/2012/06/mysql-global-unique-ids-or-guids/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Improving Yii CBreadcrumbs</title>
		<link>http://tariffstreet.com/yii/2012/06/improving-yii-cbreadcrumbs/</link>
		<comments>http://tariffstreet.com/yii/2012/06/improving-yii-cbreadcrumbs/#comments</comments>
		<pubDate>Tue, 12 Jun 2012 07:40:05 +0000</pubDate>
		<dc:creator>Harry Bailey</dc:creator>
				<category><![CDATA[Code Examples]]></category>

		<guid isPermaLink="false">http://tariffstreet.com/yii/?p=86</guid>
		<description><![CDATA[Note: As of Yii 1.1.11 CBreadcrumbs now has more options which allow you to create Bootstrap style breadcrumbs without the method below&#8230; $this->widget('zii.widgets.CBreadcrumbs', array( 'links' => array( 'businesses' => array('business/index'), 'Ikea' => array('business/view', 'id' => '123'), 'Update', ), 'homeLink' => &#8230; <a href="http://tariffstreet.com/yii/2012/06/improving-yii-cbreadcrumbs/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Note:</strong> As of Yii 1.1.11 CBreadcrumbs now has more options which allow you to create Bootstrap style breadcrumbs without the method below&#8230;</p>
<pre>
$this->widget('zii.widgets.CBreadcrumbs', array(
	'links' => array(
		'businesses' => array('business/index'),
		'Ikea' => array('business/view', 'id' => '123'),
		'Update',
	),
	'homeLink' => false,
	'separator' => '',
	'tagName' => 'ul',
	'inactiveLinkTemplate' => '&lt;li>&lt;span>{label}&lt;/span>&lt;/li>',
	'activeLinkTemplate' => '&lt;li>&lt;a href="{url}">{label}&lt;/a> &lt;span class="divider">/&lt;/span>&lt;/li>',
	'htmlOptions' => array('class' => 'breadcrumb'),
));
</pre>
<p><strong>Original post:</strong></p>
<p>The default breadcrumbs in yii (CBreadcrumbs) do a job. Not very well, but they do it.</p>
<p>Ideally breadcrumbs should be an unordered list containing anchor tags for maximum styling options. Yii uses a div with a list of anchor tags.</p>
<p>I used to put up with it, but as the infinitely useful Twitter Bootstrap uses an unordered list for their own breadcrumbs I decided enough was enough.</p>
<p>So here is how to create your own breadcrumbs that use an unordered list, list items and anchor tags&#8230;</p>
<p>The first thing we need is to create our own component which extends CWidget, as that&#8217;s how we&#8217;ll include our breadcrumb into a view.</p>
<p>Create a file called <strong>Breadcrumb.php</strong> into <strong>protected/components</strong> with the following contents:</p>
<pre>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;"><span class="kw2">&lt;?php</span>

<span class="kw2">class</span> BreadCrumb <span class="kw2">extends</span> CWidget
<span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="re0">$crumbs</span> <span class="sy0">=</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="re0">$divider</span> <span class="sy0">=</span> <span class="st_h">' / '</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="re0">$homeLink</span> <span class="sy0">=</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st_h">'Home'</span> <span class="sy0">=&gt;</span> <span class="kw4">false</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="re0">$htmlOptions</span> <span class="sy0">=</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>

&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> run<span class="br0">&#40;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">render</span><span class="br0">&#40;</span><span class="st_h">'breadcrumb'</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
<span class="br0">&#125;</span>

<span class="sy1">?&gt;</span></div>
</div>
</pre>
<p>Next we need to create a view file for it. If you don&#8217;t already have one add a view folder to the <strong>protected/components</strong> folder and then create a new file in there called <strong>breadcrumb.php</strong> (so protected/components/views/breadcrumb.php) with the following contents:</p>
<pre>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;">&lt;ul<span class="kw2">&lt;?php</span> <span class="kw1">echo</span> <span class="br0">&#40;</span><span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">htmlOptions</span><span class="br0">&#91;</span><span class="st_h">'class'</span><span class="br0">&#93;</span> ? <span class="st_h">' class=&quot;'</span> <span class="sy0">.</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">htmlOptions</span><span class="br0">&#91;</span><span class="st_h">'class'</span><span class="br0">&#93;</span> <span class="sy0">.</span> <span class="st_h">'&quot;'</span> <span class="sy0">:</span> <span class="st_h">''</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="sy1">?&gt;</span>&gt;
<span class="kw2">&lt;?php</span> 

<span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">crumbs</span> <span class="kw1">as</span> <span class="re0">$k</span> <span class="sy0">=&gt;</span> <span class="re0">$crumb</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">echo</span> <span class="st_h">'&lt;li'</span> <span class="sy0">.</span> <span class="br0">&#40;</span><span class="re0">$crumb</span><span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span> ? <span class="st_h">' class=&quot;active&quot;'</span> <span class="sy0">:</span> <span class="st_h">''</span><span class="br0">&#41;</span> <span class="sy0">.</span> <span class="st_h">'&gt;'</span><span class="sy0">;</span>

&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$crumb</span><span class="br0">&#91;</span>1<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">echo</span> CHtml<span class="sy0">::</span><a href="http://www.php.net/link"><span class="kw3">link</span></a><span class="br0">&#40;</span><span class="re0">$crumb</span><span class="br0">&#91;</span>0<span class="br0">&#93;</span><span class="sy0">,</span> <span class="re0">$crumb</span><span class="br0">&#91;</span>1<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">echo</span> <span class="re0">$crumb</span><span class="br0">&#91;</span>0<span class="br0">&#93;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>

&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/sizeof"><span class="kw3">sizeof</span></a><span class="br0">&#40;</span><span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">crumbs</span><span class="br0">&#41;</span> <span class="sy0">&gt;</span> <span class="br0">&#40;</span><span class="re0">$k</span><span class="sy0">+</span>1<span class="br0">&#41;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">echo</span> <span class="st_h">'&lt;span class=&quot;divider&quot;&gt;'</span> <span class="sy0">.</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">divider</span> <span class="sy0">.</span> <span class="st_h">'&lt;/span&gt;'</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>

&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">echo</span> <span class="st_h">'&lt;/li&gt;'</span><span class="sy0">;</span>
<span class="br0">&#125;</span>

<span class="sy1">?&gt;</span>
&lt;/ul&gt;</div>
</div>
</pre>
<p>And finally how to use it. Well select your view and inject the following code:</p>
<pre>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;"><span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">widget</span><span class="br0">&#40;</span><span class="st_h">'application.components.BreadCrumb'</span><span class="sy0">,</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'divider'</span> <span class="sy0">=&gt;</span> <span class="st_h">'/'</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'htmlOptions'</span> <span class="sy0">=&gt;</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'class'</span> <span class="sy0">=&gt;</span> <span class="st_h">'breadcrumb'</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'crumbs'</span><span class="sy0">=&gt;</span>array<span class="br0">&#40;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st_h">'Home'</span><span class="sy0">,</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st_h">'site/index'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st_h">'Organisations'</span><span class="sy0">,</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st_h">'organisation/index'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st_h">'Acme Inc.'</span><span class="sy0">,</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st_h">'organisation/view'</span><span class="sy0">,</span> <span class="st_h">'id'</span> <span class="sy0">=&gt;</span> 3<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st_h">'Update Business'</span><span class="sy0">,</span> <span class="kw4">null</span><span class="br0">&#41;</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="sy0">,</span>
<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
</pre>
<p>Which should then give you something like the following html (which twitter bootstrap will love because we&#8217;ve used the correct html and included the breadcrumb class on the ul and divider class on the divider)&#8230;</p>
<pre>
<div class="codesnip-container" >
<div class="html4strict codesnip" style="font-family:monospace;"><span class="sc2">&lt;<a href="http://december.com/html/4/element/ul.html"><span class="kw2">ul</span></a> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;breadcrumb&gt;</span></span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;/&quot;</span>&gt;</span>Home<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<a href="http://december.com/html/4/element/span.html"><span class="kw2">span</span></a> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;divider&quot;</span>&gt;</span>/<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/span.html"><span class="kw2">span</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;/organisation&quot;</span>&gt;</span>Organisations<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<a href="http://december.com/html/4/element/span.html"><span class="kw2">span</span></a> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;divider&quot;</span>&gt;</span>/<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/span.html"><span class="kw2">span</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;/organisation/2&quot;</span>&gt;</span>Acme Inc.<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a>&gt;&lt;<a href="http://december.com/html/4/element/span.html"><span class="kw2">span</span></a> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;divider&quot;</span>&gt;</span>/<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/span.html"><span class="kw2">span</span></a>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>Update Business<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/li.html"><span class="kw2">li</span></a>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/ul.html"><span class="kw2">ul</span></a>&gt;</span></div>
</div>
</pre>
<p>Hopefully that&#8217;s of some use to you. You could easily extend it to allow a container element to be added or to bring back the default &#8216;homeLink&#8217; option.</p>
]]></content:encoded>
			<wfw:commentRss>http://tariffstreet.com/yii/2012/06/improving-yii-cbreadcrumbs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>choose RegisterCoreScript position in page html</title>
		<link>http://tariffstreet.com/yii/2012/06/choose-registercorescript-position-in-page-html/</link>
		<comments>http://tariffstreet.com/yii/2012/06/choose-registercorescript-position-in-page-html/#comments</comments>
		<pubDate>Thu, 07 Jun 2012 13:48:39 +0000</pubDate>
		<dc:creator>Harry Bailey</dc:creator>
				<category><![CDATA[Code Examples]]></category>

		<guid isPermaLink="false">http://tariffstreet.com/yii/?p=78</guid>
		<description><![CDATA[By default&#8230; Yii::App()->clientScript->registerCoreScript('jquery'); &#8230;will include the script tag for the jQuery core script inside the head of your page immediately before your title tag. There are times when you will want to include it just after the opening body tag &#8230; <a href="http://tariffstreet.com/yii/2012/06/choose-registercorescript-position-in-page-html/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>By default&#8230;</p>
<pre>Yii::App()->clientScript->registerCoreScript('jquery');</pre>
<p>&#8230;will include the script tag for the jQuery core script inside the head of your page immediately before your title tag.</p>
<p>There are times when you will want to include it just after the opening body tag and just before the closing body tag.</p>
<p>CClientScript::POS_HEAD will be positioned in the head just before the title tag<br />
CClientScript::POS_BEGIN will be positioned immediately after the opening body tag<br />
CClientScript::POS_END will be position immediately before the closing body tag</p>
<p>You have two ways to specify the location you would like. You can include your choice in the config/main.php file (or your own config file)&#8230;</p>
<pre>
'clientScript'=>array(
    'coreScriptPosition' => CClientScript::POS_END,
),
</pre>
<p>&#8230;inside the components array.</p>
<p>Or you can specify it in a controller or view (usually just before you register the core script(s) using&#8230;</p>
<pre>Yii::app()->clientScript->coreScriptPosition=CClientScript::POS_END;</pre>
<p>Remembering to update POS_END with your chosen position.</p>
]]></content:encoded>
			<wfw:commentRss>http://tariffstreet.com/yii/2012/06/choose-registercorescript-position-in-page-html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing Cron jobs with Yii and CConsoleCommand</title>
		<link>http://tariffstreet.com/yii/2012/04/implementing-cron-jobs-with-yii-and-cconsolecommand/</link>
		<comments>http://tariffstreet.com/yii/2012/04/implementing-cron-jobs-with-yii-and-cconsolecommand/#comments</comments>
		<pubDate>Mon, 16 Apr 2012 08:42:19 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Code Examples]]></category>

		<guid isPermaLink="false">http://tariffstreet.com/yii/?p=60</guid>
		<description><![CDATA[A site I&#8217;m currently building requires a bunch of Cron jobs running daily to bring in and update various bits of data. It&#8217;s the first time I&#8217;ve needed to do this within the Yii framework, and it was a useful &#8230; <a href="http://tariffstreet.com/yii/2012/04/implementing-cron-jobs-with-yii-and-cconsolecommand/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A site I&#8217;m currently building requires a bunch of Cron jobs running daily to bring in and update various bits of data. It&#8217;s the first time I&#8217;ve needed to do this within the Yii framework, and it was a useful experience figuring out how it works. The Yii documentation located at http://www.yiiframework.com/wiki/91/implementing-cron-jobs-with-yii/ isn&#8217;t completely clear, so hopefully this post will help.</p>
<p>Firstly, forget about browser emulation, the best way to implement Cron jobs in Yii is by using Yii&#8217;s Console Application (CConsoleCommand) functions.</p>
<p>Essentially this is a separate instance of your application that can be run from the command line rather than as a publicly executable php script.</p>
<p>The first thing to do is to create a new entry or index script &#8211; which looks a lot like the index.php file in your public_html or root directory. However, for extra security your new index script can be (and probably should be) placed outside of the public root so you can only access it through the command line.</p>
<p>I called my script cron.php and dropped it on to the server below public_html. The file will look something like this:</p>
<pre>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;"><span class="co1">// change the following paths if necessary</span>
<span class="re0">$yii</span><span class="sy0">=</span><a href="http://www.php.net/dirname"><span class="kw3">dirname</span></a><span class="br0">&#40;</span><span class="kw4">__FILE__</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st_h">'/framework/yii.php'</span><span class="sy0">;</span>
<span class="re0">$config</span><span class="sy0">=</span><a href="http://www.php.net/dirname"><span class="kw3">dirname</span></a><span class="br0">&#40;</span><span class="kw4">__FILE__</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st_h">'/public_html/protected/config/cron.php'</span><span class="sy0">;</span>

<span class="co1">// remove the following lines when in production mode</span>
<a href="http://www.php.net/defined"><span class="kw3">defined</span></a><span class="br0">&#40;</span><span class="st_h">'YII_DEBUG'</span><span class="br0">&#41;</span> or <a href="http://www.php.net/define"><span class="kw3">define</span></a><span class="br0">&#40;</span><span class="st_h">'YII_DEBUG'</span><span class="sy0">,</span><span class="kw4">true</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">// specify how many levels of call stack should be shown in each log message</span>
<a href="http://www.php.net/defined"><span class="kw3">defined</span></a><span class="br0">&#40;</span><span class="st_h">'YII_TRACE_LEVEL'</span><span class="br0">&#41;</span> or <a href="http://www.php.net/define"><span class="kw3">define</span></a><span class="br0">&#40;</span><span class="st_h">'YII_TRACE_LEVEL'</span><span class="sy0">,</span>3<span class="br0">&#41;</span><span class="sy0">;</span>

<span class="kw1">require_once</span><span class="br0">&#40;</span><span class="re0">$yii</span><span class="br0">&#41;</span><span class="sy0">;</span>

<span class="re0">$app</span> <span class="sy0">=</span> Yii<span class="sy0">::</span><span class="me2">createConsoleApplication</span><span class="br0">&#40;</span><span class="re0">$config</span><span class="br0">&#41;</span><span class="sy0">-&gt;</span><span class="me1">run</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
</pre>
<p>Two things to notice here. Firstly the $config information comes from a new config file I&#8217;ve called cron.php. This is very much like your main.php config file, except it contains a lot less stuff:</p>
<pre>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;"><span class="kw1">return</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'basePath'</span><span class="sy0">=&gt;</span>dirname<span class="br0">&#40;</span><span class="kw4">__FILE__</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="kw4">DIRECTORY_SEPARATOR</span><span class="sy0">.</span><span class="st_h">'..'</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'name'</span><span class="sy0">=&gt;</span><span class="st_h">'Cron'</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'preload'</span><span class="sy0">=&gt;</span>array<span class="br0">&#40;</span><span class="st_h">'log'</span><span class="br0">&#41;</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st_h">'import'</span><span class="sy0">=&gt;</span>array<span class="br0">&#40;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'application.components.*'</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'application.models.*'</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// application components</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'components'</span><span class="sy0">=&gt;</span>array<span class="br0">&#40;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'db'</span><span class="sy0">=&gt;</span>array<span class="br0">&#40;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'connectionString'</span> <span class="sy0">=&gt;</span> <span class="st_h">'mysql:host=localhost;dbname=db_name'</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'emulatePrepare'</span> <span class="sy0">=&gt;</span> <span class="kw4">true</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'username'</span> <span class="sy0">=&gt;</span> <span class="st_h">'root'</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'password'</span> <span class="sy0">=&gt;</span> <span class="st_h">''</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'charset'</span> <span class="sy0">=&gt;</span> <span class="st_h">'utf8'</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'enableProfiling'</span> <span class="sy0">=&gt;</span> <span class="kw4">true</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'log'</span><span class="sy0">=&gt;</span>array<span class="br0">&#40;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'class'</span><span class="sy0">=&gt;</span><span class="st_h">'CLogRouter'</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'routes'</span><span class="sy0">=&gt;</span>array<span class="br0">&#40;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'class'</span><span class="sy0">=&gt;</span><span class="st_h">'CFileLogRoute'</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'logFile'</span><span class="sy0">=&gt;</span><span class="st_h">'cron.log'</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'levels'</span><span class="sy0">=&gt;</span><span class="st_h">'error, warning'</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'class'</span><span class="sy0">=&gt;</span><span class="st_h">'CFileLogRoute'</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'logFile'</span><span class="sy0">=&gt;</span><span class="st_h">'cron_trace.log'</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'levels'</span><span class="sy0">=&gt;</span><span class="st_h">'trace'</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'functions'</span><span class="sy0">=&gt;</span>array<span class="br0">&#40;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'class'</span><span class="sy0">=&gt;</span><span class="st_h">'application.extensions.functions.Functions'</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="sy0">,</span>
<span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
</pre>
<p>Secondly, you&#8217;re running Yii&#8217;s createConsoleApplication method, rather than firing up the web application.</p>
<p>Once you&#8217;ve done that, the next thing is to understand what this createConsoleApplication()->run(); whatsit is doing.</p>
<p>When this function is fired, it looks in /protected/commands for commands to run. A command takes the form of a Class file of the name YourFunctionCommand.php &#8211; yes, you must suffix it with Command.php.</p>
<p>Within this Class file you need something like</p>
<pre>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;"><span class="kw2">class</span> VisitorsCommand <span class="kw2">extends</span> CConsoleCommand
<span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> run<span class="br0">&#40;</span><span class="re0">$args</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="co1">// Do stuff</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
<span class="br0">&#125;</span></div>
</div>
</pre>
<p>So this file is called VisitorsCommand.php and the class name is VisitorsCommand &#8211; get it?</p>
<p>Now, if you were to fire up your command line interface and run something along these lines:</p>
<pre>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;"><span class="sy0">/</span>usr<span class="sy0">/</span>bin<span class="sy0">/</span>php <span class="sy0">/</span>Users<span class="sy0">/</span>james<span class="sy0">/</span>Dropbox<span class="sy0">/</span>Sites<span class="sy0">/</span>mySiteRoot<span class="sy0">/</span>cron<span class="sy0">.</span>php</div>
</div>
</pre>
<p>You&#8217;ll get a message saying </p>
<pre>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;">The following commands are available<span class="sy0">:</span>
&nbsp;<span class="sy0">-</span> visitors</div>
</div>
</pre>
<p>So now you can do </p>
<pre>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;"><span class="sy0">/</span>usr<span class="sy0">/</span>bin<span class="sy0">/</span>php <span class="sy0">/</span>Users<span class="sy0">/</span>james<span class="sy0">/</span>Dropbox<span class="sy0">/</span>Sites<span class="sy0">/</span>mySiteRoot<span class="sy0">/</span>cron<span class="sy0">.</span>php visitors</div>
</div>
</pre>
<p>And Yii will instantiate your Visitors Class and fire the run() method.</p>
<p>Also&#8230; you will notice the run() method accepts a parameter &#8211; I&#8217;ve called it $args, for the sake of argument.</p>
<p>You can pass parameters into the run method like this</p>
<pre>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;"><span class="sy0">/</span>usr<span class="sy0">/</span>bin<span class="sy0">/</span>php <span class="sy0">/</span>Users<span class="sy0">/</span>james<span class="sy0">/</span>Dropbox<span class="sy0">/</span>Sites<span class="sy0">/</span>mySiteRoot<span class="sy0">/</span>cron<span class="sy0">.</span>php visitors param1 param2 param3</div>
</div>
</pre>
<p>And they&#8217;ll end up in your run method as an array. You could for example write one Command class that can perform a variety of functions, or pass a key to validate the user of the Cron.</p>
<p>Within your new Command Class, you can access all your Models as normal to perform whatever functions you require.</p>
<p>Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://tariffstreet.com/yii/2012/04/implementing-cron-jobs-with-yii-and-cconsolecommand/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>What version of Yii are you running?</title>
		<link>http://tariffstreet.com/yii/2012/02/what-version-of-yii-are-you-running/</link>
		<comments>http://tariffstreet.com/yii/2012/02/what-version-of-yii-are-you-running/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 20:35:41 +0000</pubDate>
		<dc:creator>Harry Bailey</dc:creator>
				<category><![CDATA[Code Examples]]></category>

		<guid isPermaLink="false">http://tariffstreet.com/yii/?p=54</guid>
		<description><![CDATA[Ever been half way through a Yii development and thought &#8220;I wonder what version of yii am I using?&#8221; Finding out is as simple as sticking the following link into your page&#8230; print Yii::getVersion&#40;&#41;; Wonder no more as the currently &#8230; <a href="http://tariffstreet.com/yii/2012/02/what-version-of-yii-are-you-running/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ever been half way through a Yii development and thought &#8220;I wonder what version of yii am I using?&#8221;</p>
<p>Finding out is as simple as sticking the following link into your page&#8230;</p>
<pre>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;"><span class="kw1">print</span> Yii<span class="sy0">::</span><span class="me2">getVersion</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
</pre>
<p>Wonder no more as the currently used version will be right before your eyes!</p>
]]></content:encoded>
			<wfw:commentRss>http://tariffstreet.com/yii/2012/02/what-version-of-yii-are-you-running/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Yii extensions &#8211; Where to put site-wide functions?</title>
		<link>http://tariffstreet.com/yii/2012/01/yii-extensions-where-to-put-site-wide-functions/</link>
		<comments>http://tariffstreet.com/yii/2012/01/yii-extensions-where-to-put-site-wide-functions/#comments</comments>
		<pubDate>Sat, 21 Jan 2012 15:52:07 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Code Examples]]></category>

		<guid isPermaLink="false">http://tariffstreet.com/yii/?p=49</guid>
		<description><![CDATA[One aspect of Yii that&#8217;s confused me in the past is where to put generic site-wide functions that you want to access throughout the application. Stuff like an encryption method or a hash generator, that don&#8217;t belong to a specific &#8230; <a href="http://tariffstreet.com/yii/2012/01/yii-extensions-where-to-put-site-wide-functions/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One aspect of Yii that&#8217;s confused me in the past is where to put generic site-wide functions that you want to access throughout the application. Stuff like an encryption method or a hash generator, that don&#8217;t belong to a specific model.</p>
<p>The answer, of course, is to use Yii&#8217;s system of Extensions. Some reading through the documentation (http://www.yiiframework.com/doc/guide/1.1/en/extension.create) revealed that what I was looking for was an &#8216;Application component&#8217; which extends Yii&#8217;s existing CApplicationComponent and is then available using </p>
<pre>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;">Yii<span class="sy0">::</span><span class="me2">app</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">-&gt;</span><span class="me1">yourExtension</span><span class="sy0">-&gt;</span><span class="me1">yourMethod</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
</pre>
<p>Firstly, create a new directory within protected/extensions called &#8216;functions&#8217;.</p>
<p>Then, in there, create a new php file called &#8216;Functions.php&#8217;</p>
<p>This file is your extension class, but it must extend CApplicationComponent:</p>
<pre>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;"><span class="kw2">&lt;?php</span>

<span class="kw2">class</span> Functions <span class="kw2">extends</span> CApplicationComponent
<span class="br0">&#123;</span>
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> returnSomething<span class="br0">&#40;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="st_h">'Something'</span><span class="sy0">;</span>
&nbsp; &nbsp; <span class="br0">&#125;</span>
<span class="br0">&#125;</span>

<span class="sy1">?&gt;</span></div>
</div>
</pre>
<p>Now go to protected/config/main.php and add the reference to your class in the &#8216;components&#8217; array:</p>
<pre>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;"><span class="st_h">'components'</span><span class="sy0">=&gt;</span>array<span class="br0">&#40;</span>
&nbsp; &nbsp; <span class="st_h">'functions'</span><span class="sy0">=&gt;</span>array<span class="br0">&#40;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'class'</span><span class="sy0">=&gt;</span><span class="st_h">'application.extensions.functions.Functions'</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="sy0">,</span>
&nbsp; &nbsp; <span class="br0">&#41;</span><span class="sy0">,</span></div>
</div>
</pre>
<p>Now, all being well you can access your functions using:</p>
<pre>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;"><span class="kw2">&lt;?php</span>

<span class="kw1">print</span> Yii<span class="sy0">::</span><span class="me2">app</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">-&gt;</span><span class="me1">functions</span><span class="sy0">-&gt;</span><span class="me1">returnSomething</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>

<span class="sy1">?&gt;</span></div>
</div>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tariffstreet.com/yii/2012/01/yii-extensions-where-to-put-site-wide-functions/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Adding Criteria To Validation Rules</title>
		<link>http://tariffstreet.com/yii/2011/10/adding-criteria-to-validation-rules/</link>
		<comments>http://tariffstreet.com/yii/2011/10/adding-criteria-to-validation-rules/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 12:07:53 +0000</pubDate>
		<dc:creator>Harry Bailey</dc:creator>
				<category><![CDATA[Code Examples]]></category>

		<guid isPermaLink="false">http://tariffstreet.com/yii/?p=46</guid>
		<description><![CDATA[Sometimes you want your validation rules to be just a little bit more than the standard options available to you like &#8216;numeric&#8217;, &#8216;length&#8217; or &#8216;safe&#8217;. Occasionally you might need a value to be unique within it&#8217;s database column: array&#40;'username', 'unique', &#8230; <a href="http://tariffstreet.com/yii/2011/10/adding-criteria-to-validation-rules/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sometimes you want your validation rules to be just a little bit more than the standard options available to you like &#8216;numeric&#8217;, &#8216;length&#8217; or &#8216;safe&#8217;.</p>
<p>Occasionally you might need a value to be unique within it&#8217;s database column:</p>
<pre>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;"><a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st_h">'username'</span><span class="sy0">,</span> <span class="st_h">'unique'</span><span class="sy0">,</span> <span class="st_h">'className'</span> <span class="sy0">=&gt;</span> <span class="st_h">'User'</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
</pre>
<p>But sometimes you want unique to be more intelligent with it&#8217;s unique validation&#8230;</p>
<pre>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;"><a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st_h">'username'</span><span class="sy0">,</span> <span class="st_h">'unique'</span><span class="sy0">,</span> <span class="st_h">'className'</span> <span class="sy0">=&gt;</span> <span class="st_h">'User'</span><span class="sy0">,</span> <span class="st_h">'criteria'</span> <span class="sy0">=&gt;</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st_h">'condition'</span> <span class="sy0">=&gt;</span> <span class="st_h">'active = 1'</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span>
<span class="br0">&#41;</span></div>
</div>
</pre>
<p>The test above will only match when username is not unique AND active = 1. In the case of unique, criteria you define is appended to the existing check which would always take place.</p>
]]></content:encoded>
			<wfw:commentRss>http://tariffstreet.com/yii/2011/10/adding-criteria-to-validation-rules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding conditions to Yii model relations</title>
		<link>http://tariffstreet.com/yii/2011/10/adding-conditions-to-yii-model-relations/</link>
		<comments>http://tariffstreet.com/yii/2011/10/adding-conditions-to-yii-model-relations/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 11:22:24 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Code Examples]]></category>

		<guid isPermaLink="false">http://tariffstreet.com/yii/?p=40</guid>
		<description><![CDATA[Something I realised today is the power of adding conditions to model relations. This allows you to specify which records are returned as part of the relationship, which therefore allows you to set up several relationships for different situations. for &#8230; <a href="http://tariffstreet.com/yii/2011/10/adding-conditions-to-yii-model-relations/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Something I realised today is the power of adding conditions to model relations. This allows you to specify which records are returned as part of the relationship, which therefore allows you to set up several relationships for different situations.</p>
<p>for example:</p>
<pre>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;"><span class="st_h">'users'</span> <span class="sy0">=&gt;</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="kw2">self</span><span class="sy0">::</span><span class="me2">MANY_MANY</span><span class="sy0">,</span> <span class="st_h">'User'</span><span class="sy0">,</span> <span class="st_h">'user2project(project_id, user_id)'</span><span class="sy0">,</span> <span class="st_h">'condition'</span> <span class="sy0">=&gt;</span> <span class="st_h">'accepted = 1'</span><span class="br0">&#41;</span><span class="sy0">,</span></div>
</div>
</pre>
<p>This only brings back users who have accepted an invitation. </p>
<p>I can then also set up a new relation, called &#8216;invitedUsers&#8217; where the condition is the opposite.</p>
<p>This allows me to access the users easily:</p>
<pre>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;"><span class="re0">$project</span> <span class="sy0">=</span> Project<span class="sy0">::</span><span class="me2">model</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">-&gt;</span><span class="me1">findByPk</span><span class="br0">&#40;</span>1<span class="br0">&#41;</span><span class="sy0">;</span>

<span class="re0">$users</span> <span class="sy0">=</span> <span class="re0">$project</span><span class="sy0">-&gt;</span><span class="me1">users</span><span class="sy0">;</span>
<span class="re0">$invitedUsers</span> <span class="sy0">=</span> <span class="re0">$project</span><span class="sy0">-&gt;</span><span class="me1">invitedUsers</span><span class="sy0">;</span></div>
</div>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tariffstreet.com/yii/2011/10/adding-conditions-to-yii-model-relations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Turning on APC per site</title>
		<link>http://tariffstreet.com/yii/2011/09/turning-on-apc-per-site/</link>
		<comments>http://tariffstreet.com/yii/2011/09/turning-on-apc-per-site/#comments</comments>
		<pubDate>Wed, 28 Sep 2011 08:12:33 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://tariffstreet.com/yii/?p=34</guid>
		<description><![CDATA[The Alternative PHP Cache (APC) is commonly used with Yii applications, as it can speed up script running time by a factor of two. Compiled code is kept in shared memory for quick and easy access instead of being compiled &#8230; <a href="http://tariffstreet.com/yii/2011/09/turning-on-apc-per-site/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The Alternative PHP Cache (APC) is commonly used with Yii applications, as it can speed up script running time by a factor of two. Compiled code is kept in shared memory for quick and easy access instead of being compiled each time a script is ran.</p>
<p>The only problem this can bring, is that if you a developing a site and APC is on, you won&#8217;t see any changes in your PHP code until APC is flushed.<br />
<span id="more-34"></span><br />
Yii has a development mode which will turn off APC for you, however, if you&#8217;re running your Yii site on a shared server, you don&#8217;t want APC on universally.</p>
<p>So, the solution is to install APC, but to only turn enable on a per site basis using .htaccess.</p>
<p>Assuming you&#8217;ve installed APC from PECL<br />
edit your php.ini and turn off APC by modifying the following line</p>
<pre>
<div class="codesnip-container" >apc.cache_by_default 0</div>
</pre>
<p>And then add the following to your site&#8217;s .htaccess or (php.ini without the &#8216;php_flag&#8217; if you&#8217;re running suPHP) when you want to turn it back on.</p>
<pre>
<div class="codesnip-container" >php_flag apc.cache_by_default On</div>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tariffstreet.com/yii/2011/09/turning-on-apc-per-site/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
