<?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>Code@HexFlux &#187; php</title>
	<atom:link href="http://code.hexflux.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://code.hexflux.com</link>
	<description>yet another web application developer using cakephp &#124;&#124; django</description>
	<lastBuildDate>Thu, 01 Apr 2010 10:43:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Easier Search&#124;&#124;Filtering With Controller::postConditions()</title>
		<link>http://code.hexflux.com/2009/06/easier-searchfiltering-with-controllerpostconditions/</link>
		<comments>http://code.hexflux.com/2009/06/easier-searchfiltering-with-controllerpostconditions/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 04:54:27 +0000</pubDate>
		<dc:creator>Hizam Mohd</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[postCondition]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://code.hexflux.com/?p=80</guid>
		<description><![CDATA[Using postCondition to simplify your search or filtering feature.]]></description>
			<content:encoded><![CDATA[<p>In the old days, I remember being extra lazy when it comes to requests for filter/search functions. I would be lazier if the conditions includes lots of fields.</p>
<p>Stumbling upon postConditions, this flipped what I felt about creating a filter function.</p>
<p>So here&#8217;s what we are going to try, we&#8217;ll create a filter function for messages as example. Let&#8217;s assume you have the table, model, controller and some CRUD done and working for messages.</p>
<p>Let us begin by creating the view first since we&#8217;re getting the filter conditions from the form. It&#8217;s this file: &#8216;app/views/messages/filter_messages.ctp&#8217;.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
&lt;h2&gt;Filter Messages&lt;/h2&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Message'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'filter_messages'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'from'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">end</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Submit Filter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;hr /&gt;
&lt;h2&gt;Filter Results: &lt;/h2&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//display apa kita jumpa kat sini</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$messages</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Message'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;hr /&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Then add the filter function to the app/controllers/messages_controller.php.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> filter_messages<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//simple initialization for the variable that'll carry the result</span>
        <span style="color: #000088;">$messages</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: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//checks if we sent something to filter via the form (remember sent items go to $this-&gt;data)</span>
        <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;">data</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">/*
             * here comes postConditions
             * first parameter is the posted value,
             * 
             * the second parameter (array('message' =&gt; 'LIKE'))
             * tells postCondition for the fields we're looking at and what type of
             * condition we want to use for that field item. So in this case, we want to use 'LIKE' for field 'message'
             * therefore the sql generated will look similar to &quot;SELECT * FROM messages as Message WHERE Message.message LIKE '%whatever%' &quot;
             * 
             * the third parameter, will tell what is the boolean condition among each
             * condition we set for the find (you know like if we want 'message' is like 'b' AND the message came from 'dude')
             * 
             * last and quite least (heh), if we set true, only the fields we set in the second parameter will be considered. 
             * if false, any field in $this-&gt;data will be used. nifty huh.
             */</span>
            <span style="color: #000088;">$conditions</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">postConditions</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: #339933;">,</span>
                                                 <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'message'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'LIKE'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                                                 <span style="color: #0000ff;">'OR'</span><span style="color: #339933;">,</span>
                                                 <span style="color: #009900; font-weight: bold;">false</span>
                                               <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//the usual find() function.</span>
            <span style="color: #000088;">$messages</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'all'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'conditions'</span><span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$conditions</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//sends result to the view.</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="color: #0000ff;">'messages'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$messages</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>That&#8217;s it!</p>
<p>An additional note: Controller::postConditions() doesn&#8217;t mean you have to use the data posted but you can also ready your own array in the usual $myarray['Model']['field1'] format and use that as parameter.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
 <span style="color: #000088;">$tobefiltered</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Message'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#40;</span>
                        <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                               <span style="color: #0000ff;">'message'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'this is my message'</span><span style="color: #339933;">,</span>
                               <span style="color: #0000ff;">'created'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'2009-09-09 21:09:09'</span><span style="color: #339933;">,</span>
                               <span style="color: #0000ff;">'from'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'013xxxxxxxxxx'</span>
                              <span style="color: #009900;">&#41;</span>
                       <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$condition_generated</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">postConditions</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tobefiltered</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://code.hexflux.com/2009/06/easier-searchfiltering-with-controllerpostconditions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Second Day On Building Drupal Module</title>
		<link>http://code.hexflux.com/2009/06/second-day-on-building-drupal-module/</link>
		<comments>http://code.hexflux.com/2009/06/second-day-on-building-drupal-module/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 03:59:36 +0000</pubDate>
		<dc:creator>Hizam Mohd</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[modules]]></category>
		<category><![CDATA[qna]]></category>

		<guid isPermaLink="false">http://code.hexflux.com/?p=75</guid>
		<description><![CDATA[Me on drupal module development]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m learning how to build a Drupal CMS module for a website I&#8217;m partially supporting.</p>
<p>The module is simply to allow a student to send in queries to a panel of teachers. A registered student submits a question, the panel gets a notification via email that a question was submitted and then the panel would answer if they want to. Quite a simple module but since I&#8217;m just starting to do it the Drupal way, it would take more time than the usuals. </p>
<p>Maybe.</p>
<p>After a day of going through the tutorials, API and whatnot, I think I&#8217;ve got enough to get the module up and running. But patience is a virtue and over-confidence is the fall of many many men. So let&#8217;s just study more of this so that we can do this properly and avoid problems later on.</p>
<p style='font-size:smaller;'>note: Considering to just mutilate Drupal&#8217;s comment module to add in what I need.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.hexflux.com/2009/06/second-day-on-building-drupal-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Post-Lamp2Win</title>
		<link>http://code.hexflux.com/2009/06/post-lamp2win/</link>
		<comments>http://code.hexflux.com/2009/06/post-lamp2win/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 06:20:15 +0000</pubDate>
		<dc:creator>Hizam Mohd</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[lamp2win]]></category>
		<category><![CDATA[textpattern]]></category>

		<guid isPermaLink="false">http://code.hexflux.com/?p=71</guid>
		<description><![CDATA[I lost at lamp2win and proud of it.]]></description>
			<content:encoded><![CDATA[<p>Okay I lost!</p>
<p>But it was worth losing. There were really good people there.</p>
<p>I was assigned to TextPattern cms and the code structure was pretty easy to understand. They didn&#8217;t have (yet) any db abstraction and looking at the code didn&#8217;t feel like doing any until later. The unstable code in subversion seems to point out that they want to provide this. Or&#8230; it could be just to support some mysql forks.</p>
<p>So I started with putting in the DB layer from their newer version into the stable one. Then after several mishaps later, I had a broken MSSQL support and basically gave up after, in my opinion, lobotomising good code. So in the end I lost.</p>
<p>It was good fun. Quite a while since I had to juggle stuffs in my life and this is good practice. </p>
]]></content:encoded>
			<wfw:commentRss>http://code.hexflux.com/2009/06/post-lamp2win/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Launching the Prayers For Forgiveness Blogger Widget!</title>
		<link>http://code.hexflux.com/2008/10/launching-the-prayers-of-forgiveness-widgetbeta/</link>
		<comments>http://code.hexflux.com/2008/10/launching-the-prayers-of-forgiveness-widgetbeta/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 07:32:31 +0000</pubDate>
		<dc:creator>Hizam Mohd</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[blogger widget]]></category>
		<category><![CDATA[forgiveness]]></category>

		<guid isPermaLink="false">http://code.hexflux.com/?p=51</guid>
		<description><![CDATA[You can get it here. Blessed with this idea after Ramadhan but hope everybody, and myself, find it especially useful for the next Ramadhan. This blogger widget randomly displays one prayer (english translation) from the seventy prayers written down by Hasan Al-Basri, a respected scholar born in 21 AH and brought up in the house [...]]]></description>
			<content:encoded><![CDATA[<p>You can get it <a href='http://forgiveness.hexflux.com'>here</a>.</p>
<p>Blessed with this idea after Ramadhan but hope everybody, and myself, find it especially useful for the next Ramadhan. </p>
<p>This blogger widget randomly displays one prayer (english translation) from the seventy prayers written down by Hasan Al-Basri, a respected scholar born in 21 AH and brought up in the house of Umm Salama (ra).</p>
<p>You can order the book at amazon. It&#8217;s right over <a href="http://www.amazon.com/Prayers-Forgiveness-Hasan-Basri/dp/0972835814/ref=sr_1_1?ie=UTF8&#038;s=books&#038;qid=1224835170&#038;sr=8-1">here</a>. Highly recommended!</p>
<p>As of writting, there&#8217;s about 5 prayers in the database. I&#8217;ll fill it up soonest. <img src='http://code.hexflux.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . (Update: All done.)</p>
<p>regards.</p>
<p>/** Update **/<br />
I guess this stuff is done! Works fine so far.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.hexflux.com/2008/10/launching-the-prayers-of-forgiveness-widgetbeta/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>menggunakan cakephp&#8217;s beforeFind</title>
		<link>http://code.hexflux.com/2008/09/menggunakan-cakephps-beforefind/</link>
		<comments>http://code.hexflux.com/2008/09/menggunakan-cakephps-beforefind/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 03:33:08 +0000</pubDate>
		<dc:creator>Hizam Mohd</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[beforefind]]></category>
		<category><![CDATA[callback]]></category>

		<guid isPermaLink="false">http://code.hexflux.com/?p=39</guid>
		<description><![CDATA[I found out that on cakephp 1.2 RC3 you must use the new $Model->find() style or the query will break. 1 2 3 4 5 6 7 8 9 10 11 //in the controller use this... $this-&#62;Post-&#62;find&#40;'first', $params&#41;; &#160; //instead of the 'old' style... $this-&#62;Post-&#62;find&#40;$conditions&#41;; &#160; //so that in the model, you can do something [...]]]></description>
			<content:encoded><![CDATA[<p><i>I found out that on cakephp 1.2 RC3 you must use the new $Model->find() style or the query will break.</i> </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//in the controller use this...</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'first'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//instead of the 'old' style...</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$conditions</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//so that in the model, you can do something like this...</span>
<span style="color: #000000; font-weight: bold;">function</span> beforeFind<span style="color: #009900;">&#40;</span><span style="color: #000088;">$queryData</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$queryData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'conditions'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;`Post`.`post_type`&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;personal&quot;</span><span style="color: #339933;">;</span>
          <span style="color: #b1b100;">return</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$queryData</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</p>
<p>Ada masanya kita perlu mengubah condition carian-carian kita pada satu-satu model. Selain meletakkan condition query itu setiap kali kita melakukan find, kita boleh menggunakan function callback pada model iaitu function beforeFind(). Ia menerima satu parameter iaitu $queryData, variable array yang menyimpan maklumat untuk find seperti &#8216;conditions&#8217;, &#8216;limit&#8217;, &#8216;joins&#8217; dan sebagainya.</p>
<p><del>Tidak</del> seperti tertera pada dokumentasi cakePHP, sebenarnya untuk beforeFind  kita dapat memulangkan samada boolean (true/false) ataupun satu array . Jika kita memulangkan boolean, ia samada menjalankan query tersebut atau tidak: true untuk teruskan query, false untuk tidak membuat query.</p>
<p>Apa yang <del>tidak</del> disebut ialah jika kita mahu menukarkan apa2 pada syarat query itu, kita perlu buat perubahan pada $queryData dan pulangkan $queryData itu (return ($queryData)). Contoh&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
* ini contoh untuk menambahkan syarat pada find kita. Ini pada model AccomodationTravelBooking
**/</span>
<span style="color: #000000; font-weight: bold;">function</span> beforeFind<span style="color: #009900;">&#40;</span><span style="color: #000088;">$queryData</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$queryData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'conditions'</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: #0000ff;">&quot;`AccomodationTravelBooking.booking_type` = 'accomodation'&quot;</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">return</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$queryData</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Contoh diberi pada dokumentasi cakephp ialah jika kita tidak membenarkan query dilakukan mengikut syarat2 tertentu:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
* ini contoh untuk menambahkan syarat pada find kita. Ini pada model AccomodationTravelBooking
**/</span>
<span style="color: #000000; font-weight: bold;">function</span> beforeFind<span style="color: #009900;">&#40;</span><span style="color: #000088;">$queryData</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//kononnya id 44 tu satu ID yang kita tak benarkan untuk diquery</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$queryData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'conditions'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'AccomodationTravelBooking.id'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">44</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #b1b100;">return</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>nota update: tak baca betul2, camtu la resultnya.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.hexflux.com/2008/09/menggunakan-cakephps-beforefind/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Contoh penggunaan find dalam cakephp 1.2</title>
		<link>http://code.hexflux.com/2008/08/contoh-penggunaan-find-dalam-cakephp-12/</link>
		<comments>http://code.hexflux.com/2008/08/contoh-penggunaan-find-dalam-cakephp-12/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 07:04:49 +0000</pubDate>
		<dc:creator>Hizam Mohd</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[model]]></category>

		<guid isPermaLink="false">http://code.hexflux.com/?p=21</guid>
		<description><![CDATA[contoh menggunakan find mengikut cakephp 1.2]]></description>
			<content:encoded><![CDATA[<p>Cakephp v1.2 memperkenalkan lebih banyak pilihan untuk model::find() iaitu samada mahu mendapatkan satu rekod sahaja (&#8216;first&#8217;), mendapatkan kesemua rekod (&#8216;all&#8217;), kiraan jumlah rekod yang dicapai (&#8216;count&#8217;) ataupun dalam bentuk list untuk dimasukkan digunakan dalam dropdown list contohnya.</p>
<p>Berikut beberapa contoh penggunaannya.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//first. mendapatkan satu rekod sahaja (yang pertama dicapai oleh database)</span>
<span style="color: #000088;">$condition</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Post.user_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//capai blog-post yang dibuat oleh user 3</span>
<span style="color: #000088;">$posts_by_user</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'first'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$condition</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$posts_by_user</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Post'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//memaparkan title post berkenaan.</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//all. mendapatkan semua rekod mengikut syarat yang kita tetapkan dalam $condition</span>
<span style="color: #000088;">$condition</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Post.user_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//capai blog-post yang dibuat oleh user 3</span>
<span style="color: #000088;">$posts_by_user</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'all'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$condition</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pr<span style="color: #009900;">&#40;</span><span style="color: #000088;">$posts_by_user</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//ini akan memaparkan kandungan array iaitu kesemua rekod kepunyaan user 3</span></pre></td></tr></table></div>

<p>model::findAll() akan dibuang (deprecated) dalam versi akhir 1.2 jadi kita patut menggunakan model::find untuk mencapai rekod-rekod dalam cakephp.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//count. mengira berapa rekod yang dicapai</span>
<span style="color: #000088;">$condition</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Post.user_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//capai blog-post yang dibuat oleh user 3</span>
<span style="color: #000088;">$count_posts_by_user</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'count'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$condition</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//ini memulangkan integer</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$posts_by_user</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//akan terpapar jumlah rekod ie 6</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//list. mendapatkan senarai rekod</span>
<span style="color: #666666; font-style: italic;">//dalam bentuk yang sesuai untuk diguna dalam $form-&gt;input jenis 'select' (contohnya)</span>
<span style="color: #666666; font-style: italic;">//+++++++++++++++ controller +++++++++++++++++++++++++++//</span>
&nbsp;
<span style="color: #000088;">$states</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">State</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'list'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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="color: #0000ff;">'states'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$states</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//hantarkan kepada view...</span>
<span style="color: #666666; font-style: italic;">//+++++++++++++++ view +++++++++++++++++++++++++++//</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//di view pula...</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'negeri'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'options'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$states</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//ini akan paparkan dropdown senarai negeri.</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://code.hexflux.com/2008/08/contoh-penggunaan-find-dalam-cakephp-12/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
