<?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>cakebaker &#187; programming</title>
	<atom:link href="http://cakebaker.42dh.com/tags/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakebaker.42dh.com</link>
	<description>baking cakes with CakePHP</description>
	<lastBuildDate>Mon, 19 Jul 2010 14:23:38 +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>Usability-driven development</title>
		<link>http://cakebaker.42dh.com/2007/07/07/usability-driven-development/</link>
		<comments>http://cakebaker.42dh.com/2007/07/07/usability-driven-development/#comments</comments>
		<pubDate>Sat, 07 Jul 2007 09:37:20 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/07/07/usability-driven-development/</guid>
		<description><![CDATA[In the article &#8220;What do you do when there is no documentation?&#8221; Chris Hartjes wrote about his attempt to use the Auth component in CakePHP for which almost no documentation exists. As I wouldn&#8217;t call Chris a newbie, it made me think. Is the missing documentation really the problem? Or could it be something else [...]]]></description>
			<content:encoded><![CDATA[<p>In the article <a href="http://www.littlehart.net/atthekeyboard/2007/07/03/what-do-you-do-when-there-is-no-documentation/">&#8220;What do you do when there is no documentation?&#8221;</a> Chris Hartjes wrote about his attempt to use the Auth component in CakePHP for which almost no documentation exists. As I wouldn&#8217;t call Chris a newbie, it made me think. Is the missing documentation really the problem? Or could it be something else that makes it hard to use the component?</p>
<p>That&#8217;s when I realized it could be a usability issue. And that the &#8220;user interface&#8221; of the component is simply not understood by the users&#8230; Anyway, this post is not about possible problems of the Auth component.</p>
<p>What I want to talk about is, as the title says, usability-driven development. If you hear &#8220;usability&#8221;, you probably associate it with user interfaces and how people interact with them. And so usability-driven development will probably deal with making better user interfaces. That&#8217;s correct. But it is not about user interfaces like web pages, it is about &#8220;user interfaces&#8221; of code components.</p>
<p>I know, it sounds a bit strange. But on an abstract level you can look at the public attributes and methods plus the comments as the user interface of a code component. And the programmer, who uses the component, interacts with this user interface. You may imagine a component as a beverage vending machine: methods are buttons, method names are the button labels, and comments are descriptions of the buttons. I know, this thought model is a bit inaccurate, as parameters and attributes are missing. But it shouldn&#8217;t matter.</p>
<p>By doing some thought experiments with our imaginary beverage vending machine we can come up with the following conclusions:</p>
<ul>
<li>too many descriptions suck as nobody likes to read much before he can use something</li>
<li>good button labels help to avoid unnecessary descriptions</li>
<li>too many buttons suck as it makes it harder to find the desired button</li>
<li>the order of buttons matters as it is faster to find the desired button when the buttons are ordered</li>
<li>as it is a beverage vending machine it shouldn&#8217;t provide food</li>
</ul>
<p>These conclusions can be easily translated back to code. By doing this we will see that a lot of code is not optimal from a usability point of view&#8230;</p>
<p>To get more concrete results (e.g. whether two methods without parameters are better than a single method with a parameter) we could introduce some metrics into our thought model, e.g. the time it takes to accomplish something. </p>
<p>Ok, what can you do to improve the usability of your code? </p>
<p>I think the most important point is to get a mindset that your code components are user interfaces for others and that you want to provide a good user experience to them. So you will design your components differently (compare it with the iPod vs. traditional MP3 players). </p>
<p>It is also a good idea to follow good coding practices like testing and refactoring. </p>
<p>And last, but not least, you could do usability tests. Give your component to someone else who never used it and let him accomplish a task while you watch. It may give you some good insights into what sucks with your component ;-)</p>
<p>Ok, I hope it was not too confusing. And maybe you will now look differently at your code ;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2007/07/07/usability-driven-development/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>When programming becomes stale&#8230;</title>
		<link>http://cakebaker.42dh.com/2007/06/25/when-programming-becomes-stale/</link>
		<comments>http://cakebaker.42dh.com/2007/06/25/when-programming-becomes-stale/#comments</comments>
		<pubDate>Mon, 25 Jun 2007 17:27:39 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[life]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/06/25/when-programming-becomes-stale/</guid>
		<description><![CDATA[Over the last few weeks I noticed a growing feeling that programming becomes stale for me. And as a consequence, the motivation to program dropped more and more. Programming just doesn&#8217;t feel right anymore. I don&#8217;t know exactly why that happened. But I think it has to do with my ignorance of my purpose in [...]]]></description>
			<content:encoded><![CDATA[<p>Over the last few weeks I noticed a growing feeling that programming becomes stale for me. And as a consequence, the motivation to program dropped more and more. Programming just doesn&#8217;t feel right anymore. I don&#8217;t know exactly why that happened. But I think it has to do with my ignorance of my <a href="http://cakebaker.42dh.com/2006/10/17/finding-your-purpose-in-life/">purpose in life</a>.</p>
<p>So, how to deal with such a situation? </p>
<p>I think the most important step is to reduce the activity which makes you unhappy as soon as possible to avoid something worse like a breakdown or a burn out. Don&#8217;t stave it off, there is never an ideal time for such things! </p>
<p>The next step is to define what you want to do in the future. Should you still program? And if yes, how much? And what else could you do to earn money in the future? Difficult questions. Questions to which I don&#8217;t have answers yet&#8230;</p>
<p>From the answers to those (and probably other) questions you can then derive goals and a strategy to achieve them. The last step is to implement this strategy. </p>
<p>As you see, life comes with ups and downs. Nobody likes downs, but I think they are a good opportunity to learn. And the next up comes surely ;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2007/06/25/when-programming-becomes-stale/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Hey programmer, why don&#8217;t you code in english?</title>
		<link>http://cakebaker.42dh.com/2006/07/16/hey-programmer-why-dont-you-code-in-english/</link>
		<comments>http://cakebaker.42dh.com/2006/07/16/hey-programmer-why-dont-you-code-in-english/#comments</comments>
		<pubDate>Sun, 16 Jul 2006 12:51:31 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=227</guid>
		<description><![CDATA[It is hard to believe, at least for me, that there are still programmers out there who code in their native, non-english, language, i.e. they use non-english names for classes, methods, variables, etc. Of course, it is easier to use your native language than a foreign language. You think in your native language, and know [...]]]></description>
			<content:encoded><![CDATA[<p>It is hard to believe, at least for me, that there are still programmers out there who code in their native, non-english, language, i.e. they use non-english names for classes, methods, variables, etc. Of course, it is easier to use your native language than a foreign language. You think in your native language, and know all the words you may need without consulting a dictionary. Even though it is a bad practice to use an other language than English to write your code. Why? Let me explain.</p>
<ul>
<li>English is the defacto standard language for code. Almost all programming languages, frameworks and libraries use English for their APIs</li>
<li>Code written in one language is easier to read than code that mixes two languages (I think you wouldn&#8217;t like it if I would mix german and english words in my posts *g*)</li>
<li>Code written in a non-english language excludes a lot of programmers from understanding your code, with the following consequences:
<ul>
<li>It is more difficult to get help in newsgroups, forums, etc.</li>
<li>It is more difficult to outsource the development of parts of your application</li>
<li>Your framework or library won&#8217;t be used</li>
</ul>
</li>
</ul>
<p>You see, there are more disadvantages than advantages when using a non-english language for your code. So there is no reason to stick to your non-english language anymore (except for maintenance purposes).</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2006/07/16/hey-programmer-why-dont-you-code-in-english/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>File upload with CakePHP</title>
		<link>http://cakebaker.42dh.com/2006/04/15/file-upload-with-cakephp/</link>
		<comments>http://cakebaker.42dh.com/2006/04/15/file-upload-with-cakephp/#comments</comments>
		<pubDate>Sat, 15 Apr 2006 08:58:50 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=165</guid>
		<description><![CDATA[In this post I will describe how to upload and store a file in the database. Yes, you read correct, I will describe how to store a file in the database. I know, a lot of people do not recommend storing files in a database due to performance reasons. Of course, this is an important [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will describe how to upload and store a file in the database. Yes, you read correct, I will describe how to store a file in the database. I know, a lot of people do not recommend storing files in a database due to performance reasons. Of course, this is an important point you have to consider when you design your application. The reasons why I store files often in the database are:</p>
<ul>
<li>all data are stored in one place: the database</li>
<li>it is easier to test</li>
<li>it is easier to develop as I do not have to keep database and file system in sync</li>
</ul>
<p>Enough of bla-bla, let us dive in the code. First the table definition for MySQL:</p>
<pre>
CREATE TABLE my_files (
  id INT(11) NOT NULL AUTO_INCREMENT,
  name VARCHAR(75) NOT NULL,
  type VARCHAR(255) NOT NULL,
  size INT(11) NOT NULL,
  data MEDIUMBLOB NOT NULL,
  created DATETIME,
  modified DATETIME,
  PRIMARY KEY (id)
);
</pre>
<p>Note: Use MEDIUMBLOB or LONGBLOB as data type unless you know for sure that the file size of the uploaded files is never bigger than 64kB.</p>
<p>The model is straight-forward:</p>
<pre>
// app/models/my_file.php
class MyFile extends AppModel {
    var $name = 'MyFile';
}
</pre>
<p>We omit the controller for the moment and create directly the view:</p>
<pre>
// app/views/my_files/add.ctp  (Cake 1.2)
&lt;?php
    echo $form-&gt;create('MyFile', array('action' =&gt; 'add', 'type' =&gt; 'file'));
    echo $form-&gt;file('File');
    echo $form-&gt;submit('Upload');
    echo $form-&gt;end();
?&gt;

// app/views/my_files/add.thtml (Cake 1.1)
&lt;form action="/my_files/add" enctype="multipart/form-data" method="post"&gt;
    &lt;?php echo $html-&gt;file('File'); ?&gt;
    &lt;?php echo $html-&gt;submit('Upload'); ?&gt;
&lt;/form&gt;
</pre>
<p>So, now we are ready to build the controller and to implement the add() function:</p>
<pre>
// app/controllers/my_files_controller.php (Cake 1.2)
class MyFilesController extends AppController {
    function add() {
        if (!empty($this-&gt;data) &amp;&amp;
             is_uploaded_file($this-&gt;data['MyFile']['File']['tmp_name'])) {
            $fileData = fread(fopen($this-&gt;data['MyFile']['File']['tmp_name'], "r"),
                                     $this-&gt;data['MyFile']['File']['size']);

            $this-&gt;data['MyFile']['name'] = $this-&gt;data['MyFile']['File']['name'];
            $this-&gt;data['MyFile']['type'] = $this-&gt;data['MyFile']['File']['type'];
            $this-&gt;data['MyFile']['size'] = $this-&gt;data['MyFile']['File']['size'];
            $this-&gt;data['MyFile']['data'] = $fileData;

            $this-&gt;MyFile-&gt;save($this-&gt;data);

            $this-&gt;redirect('somecontroller/someaction');
        }
    }
}

// app/controllers/my_files_controller.php (Cake 1.1)
class MyFilesController extends AppController {
    function add() {
        if (!empty($this-&gt;params['form']) &amp;&amp;
             is_uploaded_file($this-&gt;params['form']['File']['tmp_name'])) {
            $fileData = fread(fopen($this-&gt;params['form']['File']['tmp_name'], "r"),
                                     $this-&gt;params['form']['File']['size']);
            $this-&gt;params['form']['File']['data'] = $fileData;

            $this-&gt;MyFile-&gt;save($this-&gt;params['form']['File']);

            $this-&gt;redirect('somecontroller/someaction');
        }
    }
}
</pre>
<p>Easy, isn&#8217;t it? Up to now we have stored the file in the database. To retrieve the file from the database, we need a download() action which we add to our controller:</p>
<pre>
function download($id) {
    Configure::write('debug', 0);
    $file = $this-&gt;MyFile-&gt;findById($id);

    header('Content-type: ' . $file['MyFile']['type']);
    header('Content-length: ' . $file['MyFile']['size']); // some people reported problems with this line (see the comments), commenting out this line helped in those cases
    header('Content-Disposition: attachment; filename="'.$file['MyFile']['name'].'"');
    echo $file['MyFile']['data'];

    exit();
}
</pre>
<p>Well, I know that this action is probably not very cake-like, the proper way would be to use a layout and a view, but this way I have less to write ;-) </p>
<p>So, that&#8217;s it. We have finished our very simple upload/download application.</p>
<p>Update (2006-08-05): Fixed a security hole in the code above, see also <a href="http://cakebaker.42dh.com/2006/07/25/be-careful-with-file-uploads/">&#8220;Be careful with file uploads&#8221;</a>. Thanks to Lamby.<br />
Update (2007-06-09): Fixed a small bug in the download function. Thanks to <a href="http://blog.gnallspik.net">Wilhelm Raab</a>!<br />
Update (2007-10-15): The name &#8220;File&#8221; led to problems with the core class with the same name, hence I renamed table name, model name, etc. Thanks to &#8220;fyi&#8221; for the hint!<br />
Update (2007-12-11): Updated for CakePHP 1.2.<br />
Update (2009-02-20): Adding comment to the header(&#8216;Content-length&#8217;) statement in the download method</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2006/04/15/file-upload-with-cakephp/feed/</wfw:commentRss>
		<slash:comments>146</slash:comments>
		</item>
		<item>
		<title>Conditions in CakePHP RC6</title>
		<link>http://cakebaker.42dh.com/2006/03/02/conditions-in-cakephp-rc6/</link>
		<comments>http://cakebaker.42dh.com/2006/03/02/conditions-in-cakephp-rc6/#comments</comments>
		<pubDate>Thu, 02 Mar 2006 13:58:30 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=129</guid>
		<description><![CDATA[Update (2008-09-17): Adapted code for CakePHP 1.2 RC2. I have already written about defining conditions in RC6, but unfortunately, most of it is no longer valid ;-) So, in this post I will show the current way of defining conditions. First some examples using the array syntax: $this-&#62;User-&#62;find('all', array('conditions' =&#62; array('User.firstname' =&#62; 'Daniel'))); $this-&#62;User-&#62;find('all', array('conditions' [...]]]></description>
			<content:encoded><![CDATA[<p>Update (2008-09-17): Adapted code for CakePHP 1.2 RC2.</p>
<p>I have already written about defining conditions in RC6, but unfortunately, most of it is no longer valid ;-)  So, in this post I will show the current way of defining conditions. </p>
<p>First some examples using the array syntax:</p>
<pre>
$this-&gt;User-&gt;find('all', array('conditions' =&gt; array('User.firstname' =&gt; 'Daniel')));
$this-&gt;User-&gt;find('all', array('conditions' =&gt; array('User.firstname LIKE' =&gt; '%an%'));
$this-&gt;User-&gt;find('all', array('conditions' =&gt; array('User.age &gt;' =&gt; 18));
</pre>
<p>When using several conditions in the array, they are combined with an &#8220;AND&#8221;. </p>
<p>[removed old stuff which no longer works]</p>
<p>The most flexible way is to use a simple string with your condition(s). In this case you have to single quote the values, as shown in the example:</p>
<pre>
$this-&gt;User-&gt;find('all' =&gt; array('conditions' =&gt; array("User.firstname = 'Daniel' OR User.firstname = 'Hugo'")));
</pre>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2006/03/02/conditions-in-cakephp-rc6/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Test your models</title>
		<link>http://cakebaker.42dh.com/2006/02/25/test-your-models/</link>
		<comments>http://cakebaker.42dh.com/2006/02/25/test-your-models/#comments</comments>
		<pubDate>Sat, 25 Feb 2006 13:51:55 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=121</guid>
		<description><![CDATA[I am a fan of test driven development (TDD) and so it is my goal to use this approach with CakePHP. In this post I will show you how to unit test a model. See http://wiki.cakephp.org/tutorials:testing_cake_apps for the configuration of the testing infrastructure. Let us write a model for a contact form, where the user [...]]]></description>
			<content:encoded><![CDATA[<p>I am a fan of test driven development (TDD) and so it is my goal to use this approach with CakePHP. In this post I will show you how to unit test a model. See <a href="http://wiki.cakephp.org/tutorials:testing_cake_apps">http://wiki.cakephp.org/tutorials:testing_cake_apps</a> for the configuration of the testing infrastructure. </p>
<p>Let us write a model for a contact form, where the user must enter an email address and a text. This is our model for the moment:</p>
<pre>
&lt;?php
    class Contactrequest extends AppModel
    {
    }
?&gt;
</pre>
<p>What could go wrong with our model? Theoretically nothing, as we have not written anything. But in reality, we do not know if the framework works as expected, as there are almost no test cases for the framework available. So let us test if we can save our model.</p>
<pre>
&lt;?php
class ContactrequestTest extends UnitTestCase
{
	var $model;
	var $validEmail = 'dho@xy.com';
	var $validComment = 'hello';

	function setUp()
	{
		$this-&gt;model =&amp; new Contactrequest();
		$this-&gt;model-&gt;query('DELETE FROM contactrequests');
	}

	function testSave()
	{
		$this-&gt;model-&gt;data = array('Contactrequest' =&gt; array('email' =&gt;
                                        $this-&gt;validEmail, 'comment' =&gt; $this-&gt;validComment));

		$this-&gt;assertTrue($this-&gt;model-&gt;save());
		$id = $this-&gt;model-&gt;getLastInsertId();
		$modelData = $this-&gt;model-&gt;find(array('id' =&gt; $id));
		$this-&gt;assertEqual($modelData['Contactrequest']['email'],
                                               $this-&gt;validEmail);
		$this-&gt;assertEqual($modelData['Contactrequest']['comment'],
                                               $this-&gt;validComment);
	}
}
?&gt;
</pre>
<p>If we run this test case, we get a green bar. Cool! So we go on and write tests to ensure that contact requests with an invalid email address or an empty comment cause a validation error.</p>
<pre>
function testSaveWithEmptyComment()
{
    $this-&gt;model-&gt;data = array('Contactrequest' =&gt; array('email' =&gt;
                                                    $this-&gt;validEmail, 'comment' =&gt; ''));

    $this-&gt;assertFalse($this-&gt;model-&gt;save());
    $this-&gt;assertFalse(isset($this-&gt;model-&gt;validationErrors['email']));
    $this-&gt;assertEqual($this-&gt;model-&gt;validationErrors['comment'], '1');
}

function testSaveWithInvalidEmail()
{
    $this-&gt;model-&gt;data = array('Contactrequest' =&gt; array('email' =&gt;
                                                   'dho@xy', 'comment' =&gt; $this-&gt;validComment));

    $this-&gt;assertFalse($this-&gt;model-&gt;save());
    $this-&gt;assertFalse(isset($this-&gt;model-&gt;validationErrors['comment']));
    $this-&gt;assertEqual($this-&gt;model-&gt;validationErrors['email'], '1');
}
</pre>
<p>Ok, we can run our test case. We get, as expected, a red bar (because we have not defined any validation rules in our model). So we add the validation rules to our model:</p>
<pre>
&lt;?php
    class Contactrequest extends AppModel
    {
        var $validate = array('email' =&gt; array(array(VALID_EMAIL)),
                                            'comment' =&gt; array(array(VALID_NOT_EMPTY)));
    }
?&gt;
</pre>
<p>(Notice: The definition of the validation rules is slightly different from the standard way as I use the validation approach I described in an earlier <a href="http://cakebaker.42dh.com/2006/02/06/yet-another-data-validation-approach/">post</a>)</p>
<p>And now we run our testcase again: a green bar! With that we have finished our first tested model.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2006/02/25/test-your-models/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>New syntax for conditions II</title>
		<link>http://cakebaker.42dh.com/2006/02/21/new-syntax-for-conditions-ii/</link>
		<comments>http://cakebaker.42dh.com/2006/02/21/new-syntax-for-conditions-ii/#comments</comments>
		<pubDate>Tue, 21 Feb 2006 09:41:40 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[feature]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=116</guid>
		<description><![CDATA[Yesterday, I wrote already about the new syntax for conditions. Well, most of it is outdated today ;-) The examples I showed do no longer work, they cause an &#8220;sql syntax&#8221; error: $this-&#62;User-&#62;findAll(array('User.firstname' =&#62; '= Daniel')); $this-&#62;User-&#62;findAll(array('User.firstname' =&#62; 'LIKE %an%')); $this-&#62;User-&#62;findAll(array('User.age' =&#62; '&#62; 18')); To make them work again, we have to add a space [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I wrote already about the <a href="http://cakebaker.wordpress.com/2006/02/20/new-syntax-for-conditions/">new syntax for conditions</a>. Well, most of it is outdated today ;-)  The examples I showed do no longer work, they cause an &#8220;sql syntax&#8221; error:</p>
<pre>
$this-&gt;User-&gt;findAll(array('User.firstname' =&gt; '= Daniel'));
$this-&gt;User-&gt;findAll(array('User.firstname' =&gt; 'LIKE %an%'));
$this-&gt;User-&gt;findAll(array('User.age' =&gt; '&gt; 18'));
</pre>
<p>To make them work again, we have to add a space to the values:</p>
<pre>
$this-&gt;User-&gt;findAll(array('User.firstname' =&gt; ' = Daniel'));
$this-&gt;User-&gt;findAll(array('User.firstname' =&gt; ' LIKE %an%'));
$this-&gt;User-&gt;findAll(array('User.age' =&gt; ' &gt; 18'));
</pre>
<p>There are also some new features. By default, all conditions are concatenated with &#8220;AND&#8221;. If you want to use an &#8220;OR&#8221;, you have to do it in the following way:</p>
<pre>
$this-&gt;User-&gt;findAll(array('User.firstname' =&gt; ' = Daniel',
                                               ' OR User.firstname' =&gt; ' = Hugo'));
</pre>
<p>It is now also possible to use &#8220;&#8211;return&#8221; for a value, i.e. your value will not be quoted by CakePHP. Example:</p>
<pre>
$this-&gt;User-&gt;findAll(array('User.firstname' =&gt; "--return = 'Daniel'"));
</pre>
<p>Update (2006-02-28): <strong>The examples in this post are no longer valid!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2006/02/21/new-syntax-for-conditions-ii/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>New syntax for conditions</title>
		<link>http://cakebaker.42dh.com/2006/02/20/new-syntax-for-conditions/</link>
		<comments>http://cakebaker.42dh.com/2006/02/20/new-syntax-for-conditions/#comments</comments>
		<pubDate>Mon, 20 Feb 2006 13:40:21 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[feature]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=115</guid>
		<description><![CDATA[RC5 is still warm, but the development goes on ;-) And so a new syntax has been added for conditions. With &#8220;&#8211;return&#8221; you can avoid that your condition is quoted. Example: $this-&#62;User-&#62;findAll('--return User.company_id = 1'); That generates something like ... WHERE User.company_id = 1 ... That feature is useful if you have complex conditions you [...]]]></description>
			<content:encoded><![CDATA[<p>RC5 is still warm, but the development goes on ;-) And so a new syntax has been added for conditions. With &#8220;&#8211;return&#8221; you can avoid that your condition is quoted. Example:</p>
<pre>
$this-&gt;User-&gt;findAll('--return User.company_id = 1');
</pre>
<p>That generates something like</p>
<pre>
... WHERE User.company_id = 1 ...
</pre>
<p>That feature is useful if you have complex conditions you cannot express in another way with CakePHP. But be careful using it if your application should work with different databases.</p>
<p>The more important change is the way you can specify the conditions. Some examples:</p>
<pre>
$this-&gt;User-&gt;findAll(array('User.firstname' =&gt; '= Daniel'));
$this-&gt;User-&gt;findAll(array('User.firstname' =&gt; 'LIKE %an%'));
$this-&gt;User-&gt;findAll(array('User.age' =&gt; '&gt; 18'));
</pre>
<p>That also works for the following operators: &lt;&gt;, &gt;=, &lt;=, and &lt;.</p>
<p>Update (2006-02-21): The examples about specifying the conditions are no longer valid, see <a href="http://cakebaker.wordpress.com/2006/02/21/new-syntax-for-conditions-ii/">New syntax for conditions II</a>.</p>
<p>Update (2006-02-22): <strong>All examples in this post are no longer valid!</strong></p>
<p>Update (2006-02-28): The last three examples are valid again in RC6 ;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2006/02/20/new-syntax-for-conditions/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Webservices with CakePHP</title>
		<link>http://cakebaker.42dh.com/2006/02/17/webservices-with-cakephp/</link>
		<comments>http://cakebaker.42dh.com/2006/02/17/webservices-with-cakephp/#comments</comments>
		<pubDate>Fri, 17 Feb 2006 09:22:20 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[webservices]]></category>

		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=110</guid>
		<description><![CDATA[At the moment, CakePHP does not have built-in support for webservices (but it is planned for version 1.0). Miguel Ros could not wait until that feature is available, so he experimented a little bit. He presents two approaches using the NuSOAP toolkit in his blog (approach 1, approach 2). I prefer the second approach as [...]]]></description>
			<content:encoded><![CDATA[<p>At the moment, CakePHP does not have built-in support for webservices (but it is planned for version 1.0). Miguel Ros could not wait until that feature is available, so he experimented a little bit. He presents two approaches using the <a href="http://sourceforge.net/projects/nusoap/">NuSOAP toolkit</a> in his blog (<a href="http://rossoft.wordpress.com/2006/02/16/web-services-in-cakephp/">approach 1</a>, <a href="http://rossoft.wordpress.com/2006/02/16/webservices-in-cakephp-other-approach/">approach 2</a>). I prefer the second approach as it looks more cake-like. </p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2006/02/17/webservices-with-cakephp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Values of input fields in the same array</title>
		<link>http://cakebaker.42dh.com/2006/02/15/values-of-input-fields-in-the-same-array/</link>
		<comments>http://cakebaker.42dh.com/2006/02/15/values-of-input-fields-in-the-same-array/#comments</comments>
		<pubDate>Wed, 15 Feb 2006 10:36:17 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=107</guid>
		<description><![CDATA[Today, Petr Vytlacil asked me how to create input fields with the html helper so that the values are in the same array, i.e. how to create something like: &#60;input name="data[Price][price][]" value= "" /&#62; &#60;input name="data[Price][price][]" value= "" /&#62; The obvious approach with $html-&#62;inputTag('Price/price[]'); does not work, as it creates a wrong name: &#60;input name="data[Price][price[]]" [...]]]></description>
			<content:encoded><![CDATA[<p>Today, Petr Vytlacil asked me how to create input fields with the html helper so that the values are in the same array, i.e. how to create something like:</p>
<pre>
&lt;input name="data[Price][price][]" value= "" /&gt;
&lt;input name="data[Price][price][]" value= "" /&gt;
</pre>
<p>The obvious approach with </p>
<pre>
$html-&gt;inputTag('Price/price[]');
</pre>
<p>does not work, as it creates a wrong name:</p>
<pre>
&lt;input  name="data[Price][price[]]" value="" /&gt;
</pre>
<p>If we look at this output, we can see, how CakePHP works: it splits &#8220;Price/size[]&#8221; on the &#8220;/&#8221; character and adds square brackets. That leads us to the following workaround:</p>
<pre>
$html-&gt;inputTag('Price/price][');
</pre>
<p>Sure, it is a little bit counterintuitive, but it does the job ;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2006/02/15/values-of-input-fields-in-the-same-array/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
