<?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"
	>

<channel>
	<title>Web is Cake</title>
	<atom:link href="http://www.webiscake.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webiscake.com</link>
	<description>Web developpement made easy</description>
	<pubDate>Fri, 15 May 2009 03:01:37 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.5</generator>
	<language>en</language>
			<item>
		<title>OpenX and HostGator shared hosting</title>
		<link>http://www.webiscake.com/openx-and-hostgator-shared-hosting/</link>
		<comments>http://www.webiscake.com/openx-and-hostgator-shared-hosting/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 03:07:37 +0000</pubDate>
		<dc:creator>Jimmy Bourassa</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.webiscake.com/?p=77</guid>
		<description><![CDATA[This post is totally unrelated to CakePHP, but oh well!
As you might have noticed, OpenX does not work on HostGator&#8217;s default shared hosting. Every ad you post on your website through OpenX will be viewable, but clicking the ad will lead to a 403 forbidden page.
It has something to do with HostGator Apache&#8217;s default configuration [...]]]></description>
			<content:encoded><![CDATA[<p>This post is totally unrelated to CakePHP, but oh well!</p>
<p>As you might have noticed, OpenX does not work on HostGator&#8217;s default shared hosting. Every ad you post on your website through OpenX will be viewable, but clicking the ad will lead to a 403 forbidden page.</p>
<p>It has something to do with HostGator Apache&#8217;s default configuration on shared hosting. Globally, it is because of some configuration of mod_security, but I don&#8217;t know what it is exactly. I found out that you can&#8217;t turn off mod_security within the .htaccess. Thanksfully, the tech team will fix you up through the live support within minutes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webiscake.com/openx-and-hostgator-shared-hosting/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Common mistakes when working with accentuated characters</title>
		<link>http://www.webiscake.com/common-mistakes-when-with-accentuated-characters/</link>
		<comments>http://www.webiscake.com/common-mistakes-when-with-accentuated-characters/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 03:30:21 +0000</pubDate>
		<dc:creator>Jimmy Bourassa</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.webiscake.com/?p=72</guid>
		<description><![CDATA[Working with accentuated characters in CakePHP can definitely be a pain if you’re unfamiliar with a few basic guidelines.
All your files must be encoded in UTF-8
Make sure all your files containing accentuated characters are encoded in UTF-8 (no BOM or it’ll screw everything up!). If your file does not have the correct encoding, any string [...]]]></description>
			<content:encoded><![CDATA[<p>Working with accentuated characters in CakePHP can definitely be a pain if you’re unfamiliar with a few basic guidelines.</p>
<h3>All your files must be encoded in UTF-8</h3>
<p>Make sure all your files containing accentuated characters are encoded in UTF-8 (no <a href="http://en.wikipedia.org/wiki/Byte-order_mark">BOM</a> or it’ll screw everything up!). If your file does not have the correct encoding, any string that contains an accentuated character will just be considered as empty, which can be frustrating to debug.</p>
<h3>Database connection must use UTF-8 encoding</h3>
<p>This will prevent elements from the database to be considered as empty.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//In /app/config/database.php</span>
<span style="color: #000000; font-weight: bold;">class</span> DATABASE_CONFIG <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$default</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="">'driver'</span> <span style="color: #339933;">=&gt;</span> <span style="">'mysql'</span><span style="color: #339933;">,</span>
		<span style="">'persistent'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">,</span>
		<span style="">'host'</span> <span style="color: #339933;">=&gt;</span> <span style="">'some_host'</span><span style="color: #339933;">,</span>
		<span style="">'login'</span> <span style="color: #339933;">=&gt;</span> <span style="">'some_user'</span><span style="color: #339933;">,</span>
		<span style="">'password'</span> <span style="color: #339933;">=&gt;</span> <span style="">'some_ow'</span><span style="color: #339933;">,</span>
		<span style="">'database'</span> <span style="color: #339933;">=&gt;</span> <span style="">'some_db'</span><span style="color: #339933;">,</span>
		<span style="">'prefix'</span> <span style="color: #339933;">=&gt;</span> <span style="">''</span><span style="color: #339933;">,</span>
		<span style="">'encoding'</span><span style="color: #339933;">=&gt;</span><span style="">'utf8'</span>
	<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Set App.Encoding to UTF-8 in core.php</h3>
<p>Actually, I’m not sure why we’re doing this, but I figured it couldn’t hurt. Everytime I start a project I make sure my App.Encoding is set to UTF-8 in core.php.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">Configure<span style="color: #339933;">::</span><span style="color: #004000;">write</span><span style="color: #009900;">&#40;</span><span style="">'App.encoding'</span><span style="color: #339933;">,</span> <span style="">'UTF-8'</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<h3>Make sure to define the charset in your html files</h3>
<p>Definitely not as hard to debug as the other, but remember to define the charset in your layout.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #990000;">echo</span> <span style="color: #000088;">$html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">charset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Hope it helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webiscake.com/common-mistakes-when-with-accentuated-characters/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Model &#8220;X&#8221; with multiple associations leading to Model &#8220;Y&#8221;</title>
		<link>http://www.webiscake.com/model-x-with-multiple-associations-leading-to-model-y/</link>
		<comments>http://www.webiscake.com/model-x-with-multiple-associations-leading-to-model-y/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 16:21:32 +0000</pubDate>
		<dc:creator>Jimmy Bourassa</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.webiscake.com/?p=68</guid>
		<description><![CDATA[This seems like a fairly common case, but it might not be obvious for everyone. While the title is not totally clear, let&#8217;s use an exemple to show where the problem lies.
Let&#8217;s say we have a Message model, which has the following fields : id, sender, receiver, created, title, text. We&#8217;d like our sender and [...]]]></description>
			<content:encoded><![CDATA[<p>This seems like a fairly common case, but it might not be obvious for everyone. While the title is not totally clear, let&#8217;s use an exemple to show where the problem lies.</p>
<p>Let&#8217;s say we have a Message model, which has the following fields : <code>id</code>, <code>sender</code>, <code>receiver</code>, <code>created</code>, <code>title</code>, <code>text</code>. We&#8217;d like our <code>sender</code> and <code>receiver</code> field to link with our User model, so from and to will contain a user id. If we were to follow CakePHP’s naming convention, we’d have two <code>user_id</code> fields, which is not going to work for obvious reasons. So this is where we have to break CakePHP&#8217;s naming convention, which can lead to some confusion. Fear not, the solution is quite simple!</p>
<p>In order for this case to work, all we have to do is change the key in our association :</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> Message <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="">'Message'</span>;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$belongsTo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #666666; font-style: italic;">//In most case, this would be User instead of Sender</span>
		<span style="">'Sender'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="">'className'</span> <span style="color: #339933;">=&gt;</span> <span style="">'User'</span><span style="color: #339933;">,</span>
				<span style="">'foreignKey'</span> <span style="color: #339933;">=&gt;</span> <span style="">'sender_id'</span>
&nbsp;
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #666666; font-style: italic;">//Same goes for Receiver</span>
		<span style="">'Receiver'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="">'className'</span> <span style="color: #339933;">=&gt;</span> <span style="">'User'</span><span style="color: #339933;">,</span>
				<span style="">'foreignKey'</span> <span style="color: #339933;">=&gt;</span> <span style="">'receiver_id'</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Once the key is changed, data returned from a find on the Message model will be broke down with these keys we just set.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webiscake.com/model-x-with-multiple-associations-leading-to-model-y/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Sort search results by relevance</title>
		<link>http://www.webiscake.com/sort-search-results-by-relevance/</link>
		<comments>http://www.webiscake.com/sort-search-results-by-relevance/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 17:12:33 +0000</pubDate>
		<dc:creator>Jimmy Bourassa</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.webiscake.com/?p=56</guid>
		<description><![CDATA[When creating a search function for your website, it is fairly important to sort results by relevance. I had to do this last week, so I might as well share how I did it.
I wanted to search the News model with simple keywords. Here&#8217;s my News table :

CREATE TABLE `news` &#40;
  `id` int&#40;11&#41; NOT [...]]]></description>
			<content:encoded><![CDATA[<p>When creating a search function for your website, it is fairly important to sort results by relevance. I had to do this last week, so I might as well share how I did it.</p>
<p>I wanted to search the News model with simple keywords. Here&#8217;s my News table :</p>

<div class="wp_syntax"><div class="code"><pre class="sql sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`news`</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">`id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`slug`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`created`</span> datetime <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`published`</span> tinyint<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`title`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">150</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`description`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`text`</span> text<span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>  <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #ff0000;">`slug`</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`slug`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>In order to keep beautiful URLs, I made a simple function in NewsController that redirects to the search function using the data submitted in post. The format is <code>param:value/param2:value </code>&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> searchToUrl<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="">'News'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$paramKey</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$paramValue</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$paramValue</span><span style="color: #339933;">!=</span><span style="color: #000000; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$paramValue</span><span style="color: #339933;">!=</span><span style="">'0'</span><span style="color: #009900;">&#41;</span>
				<span style="color: #000088;">$redirectStr</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$paramKey</span><span style="color: #339933;">.</span><span style="">':'</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$paramValue</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="">'/'</span>;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="">'action'</span><span style="color: #339933;">=&gt;</span><span style="">'search'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$redirectStr</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The search function I wrote checks for every keyword submitted and awards points when the keyword is found. Every word is worth 3 points when found in the title, 1 point when found in the main text. 4 points is also awarded for the exact match in the text and 10 points for the exact match in the title. The search function I wrote does more than just keyword search, but that&#8217;s not the point of this post, so we&#8217;ll skip it for now (if you&#8217;d like to see it all, ask away and I&#8217;ll write something about it).</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Part of the search() function in the NewsController</span>
<span style="color: #000088;">$conds</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paginate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="">'News'</span><span style="color: #339933;">=&gt;</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="">'recursive'</span><span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
		<span style="">'limit'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">15</span><span style="color: #339933;">,</span>
		<span style="">'fields'</span><span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="">'DISTINCT id'</span><span style="color: #339933;">,</span> <span style="">'slug'</span><span style="color: #339933;">,</span> <span style="">'title_fr'</span><span style="color: #339933;">,</span><span style="">'classification'</span><span style="color: #339933;">,</span>
    				 <span style="">'text_fr'</span><span style="color: #339933;">,</span> <span style="">'Reference.name'</span><span style="color: #339933;">,</span> <span style="">'datepublished'</span><span style="color: #009900;">&#41;</span>
    		<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="">'Country'</span><span style="color: #339933;">=&gt;</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="">'recurisve'</span><span style="color: #339933;">=&gt;-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
		<span style="">'fields'</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span><span style="">'id'</span><span style="color: #339933;">,</span> <span style="">'name_fr'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="">'named'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="">'keywords'</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>
	<span style="color: #666666; font-style: italic;">//Replaces ' by '', to avoid breaking the SQL queries</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="">'named'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="">'keywords'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;''&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="">'named'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="">'keywords'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #666666; font-style: italic;">//Split de keywords in an array</span>
    <span style="color: #000088;">$keywords</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_split</span><span style="color: #009900;">&#40;</span><span style="">'/[\s,]+/'</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="">'named'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="">'keywords'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>PREG_SPLIT_NO_EMPTY<span style="color: #009900;">&#41;</span>;
    <span style="color: #000088;">$condsKw</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">null</span>;
    <span style="color: #666666; font-style: italic;">//Relevance Order is a pseudo col in the SQL queries that is going to be used for order.</span>
    <span style="color: #000088;">$relOrd</span> <span style="color: #339933;">=</span> <span style="">''</span>;
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$keywords</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$keyword</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
       <span style="color: #666666; font-style: italic;">//Title</span>
    	<span style="color: #000088;">$condsKw</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;title LIKE '%$keyword%' &quot;</span>;
    	<span style="color: #666666; font-style: italic;">//Each keyword in title is worth 3 points.</span>
    	<span style="color: #000088;">$relOrd</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;+ (CASE WHEN title LIKE '%$keyword%'  THEN 3 ELSE 0  END) &quot;</span>;
&nbsp;
       <span style="color: #666666; font-style: italic;">//Text</span>
    	<span style="color: #000088;">$condsKw</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;text LIKE '%$keyword%' &quot;</span>;
    	<span style="color: #666666; font-style: italic;">//Each keyword in text is worth 1 points.</span>
    	<span style="color: #000088;">$relOrd</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;+ (CASE WHEN text LIKE '%$keyword%'  THEN 1 ELSE 0  END) &quot;</span>;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">//Must be at least 3 words and 7 chars to receive points for exact string match</span>
    <span style="color: #666666; font-style: italic;">//This can obviously be tailored to fit your needs.</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$keywords</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-&gt;</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="">'named'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="">'keywords'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-&gt;</span> <span style="color: #cc66cc;">6</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    	<span style="color: #666666; font-style: italic;">//10 points if the exact match is found in the title</span>
    	<span style="color: #000088;">$relOrd</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;+ (CASE WHEN title LIKE '%&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="">'named'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="">'keywords'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;%'  THEN 10 ELSE 0  END) &quot;</span>;
&nbsp;
    	<span style="color: #666666; font-style: italic;">//4 points if the exact match is found in the text</span>
    	<span style="color: #000088;">$relOrd</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;+ (CASE WHEN text LIKE '%&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="">'named'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="">'keywords'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;%'  THEN 4 ELSE 0  END) &quot;</span>;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">//Formats then adds the pseudo column to the field list.</span>
    <span style="color: #000088;">$relOrd</span> <span style="color: #339933;">=</span> <span style="">'('</span> <span style="color: #339933;">.</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$relOrd</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="">') AS Relevance'</span>;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paginate</span><span style="color: #009900;">&#91;</span><span style="">'News'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="">'fields'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$relOrd</span>;
    <span style="color: #000088;">$conds</span><span style="color: #009900;">&#91;</span><span style="">'AND'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">join</span><span style="color: #009900;">&#40;</span><span style="">' OR '</span><span style="color: #339933;">,</span><span style="color: #000088;">$condsKw</span><span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #666666; font-style: italic;">//Sets the order if no other order is defined in the params.</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="">'named'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="">'sort'</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>
    	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paginate</span><span style="color: #009900;">&#91;</span><span style="">'News'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="">'order'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="">'Relevance'</span><span style="color: #339933;">=&gt;</span><span style="">'DESC'</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">//Sets keywords for use in the view, this can be used to highlight the keywords in the search results</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="">'kwArr'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$keywords</span><span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #666666; font-style: italic;">//Preserves the data in the html form.</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="">'News'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="">'named'</span><span style="color: #009900;">&#93;</span>;
&nbsp;
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="">'news'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paginate</span><span style="color: #009900;">&#40;</span><span style="">'News'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$conds</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>I think everything else should be fairly straightforward (the view etc.) If not, ask away in a comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webiscake.com/sort-search-results-by-relevance/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Redirecting to the proper page after actions</title>
		<link>http://www.webiscake.com/redirecting-to-the-proper-page-after-actions/</link>
		<comments>http://www.webiscake.com/redirecting-to-the-proper-page-after-actions/#comments</comments>
		<pubDate>Sat, 29 Nov 2008 06:21:43 +0000</pubDate>
		<dc:creator>Jimmy Bourassa</dc:creator>
		
		<guid isPermaLink="false">http://localhost/webiscake/?p=32</guid>
		<description><![CDATA[A couple days ago, a client I currently work for found a little annoyance with cakePHP default&#8217;s behaviour of redirecting to the index action after a delete or edit action, thus ignoring the page you were on.
Indeed, redirecting to $this->referer wouldn&#8217;t work in this case because the data is posted to the same action, therefore [...]]]></description>
			<content:encoded><![CDATA[<p>A couple days ago, a client I currently work for found a little annoyance with cakePHP default&#8217;s behaviour of redirecting to the <em>index</em> action after a <em>delete</em> or <em>edit</em> action, thus ignoring the page you were on.</p>
<p>Indeed, redirecting to $this->referer wouldn&#8217;t work in this case because the data is posted to the same action, therefore $this->referer = $this->here. The solution is quite simple, add this code to your action:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><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;">referer</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">here</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">write</span><span style="color: #009900;">&#40;</span><span style="">'referer'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">referer</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Then, if your save method is successful, you can safely redirect with the Session variable that&#8217;s just been set :</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">read</span><span style="color: #009900;">&#40;</span><span style="">'referer'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>It&#8217;s pretty simple, but I guess it might come in handy. Thanks to TommyO from the <a href="http://irc.cakephp.org/channels">irc channel</a> for this hint!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webiscake.com/redirecting-to-the-proper-page-after-actions/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

