Category Archives: programming

Hey programmer, why don’t you code in english?

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 […]

File upload with CakePHP

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 […]

Conditions in CakePHP RC6

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->User->findAll(array(‘User.firstname’ => ‘= Daniel’)); $this->User->findAll(array(‘User.firstname’ => ‘LIKE %an%’)); $this->User->findAll(array(‘User.age’ => ‘> 18’)); When using several conditions […]

Test your models

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 for the configuration of the testing infrastructure. Let us write a model for a contact form, where the user […]

New syntax for conditions II

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 “sql syntax” error: $this->User->findAll(array(‘User.firstname’ => ‘= Daniel’)); $this->User->findAll(array(‘User.firstname’ => ‘LIKE %an%’)); $this->User->findAll(array(‘User.age’ => ‘> 18’)); To make them work again, we have to add a space […]

New syntax for conditions

RC5 is still warm, but the development goes on ;-) And so a new syntax has been added for conditions. With “–return” you can avoid that your condition is quoted. Example: $this->User->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 […]

Webservices with CakePHP

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 […]

Values of input fields in the same array

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: <input name=”data[Price][price][]” value= “” /> <input name=”data[Price][price][]” value= “” /> The obvious approach with $html->inputTag(‘Price/price[]’); does not work, as it creates a wrong name: <input name=”data[Price][price[]]” […]

Don’t break the contract!

Defining a function is like defining a contract: you specify what the user of your function has to provide so that he gets the desired result. That is a basic principle in software engineering. In this post I will show what could happen if you break such a contract. Let us have a look at […]

Yet another data validation approach

The data validation in the current version of CakePHP is limited, so different people presented alternatives (solution of tobius and Felix Geisendörfer, solution of Myles Eftos). Well, I was not fully happy with these solutions, and so I have written my own data validation thing ;-) Nonetheless, a big THANK YOU goes to the aforementioned […]