Archive for December, 2008

Dealing with different configuration for development and production box

Friday, December 12th, 2008

All right, this isn’t exactly a rocket science, it’s just something I use and find very handy.

We all develop (and test) on one computer and deploy to a different computer to make the changes live. Having to run the application in two different environments brings a challenge of using different configuration based on where the application runs.
(more…)

Populating a SELECT box with distinct values

Wednesday, December 10th, 2008

Let’s say you log events into a database table Log. Attribute event holds event type and you want to filter the log listing just by that.

Here’s what you probably try at first:

  1.  
  2. $this->set(‘events’‘list’‘fields’ => ‘DISTINCT Log.event’, ‘Log.event’)));
  3.  

It’s not gonna work and you will have to use find(‘all’) and Set::combine() to get what you want:

  1. span class=”st0″>’all’‘fields’ => ‘DISTINCT Log.event’));
  2. $this->set(‘events’,
  3.   Set::combine($events, ‘{n}.Log.event’, ‘{n}.Log.event’));
  4.  

SQL functions or keywords in CakePHP conditions

Tuesday, December 9th, 2008

For those who missed the information, starting from CakePHP 1.2 it is no longer possible to use the magic tag -! in your condition to prevent your SQL function or keyword to be enclosed in quotes.

The recommended way now is to place it into the key or not make the array associative at all. It is no longer possible to put it into the value part of the definition.

So instead of:

  1. span class=”st0″>’DATE_ADD(Payment.modified, INTERVAL 2 DAY) >’ =>  
  2.   ‘CURRENT_DATE’)

you have to use:

  1. span class=”st0″>’DATE_ADD(Payment.modified, INTERVAL 2 DAY) > CURRENT_DATE’)