Monday, July 14, 2008

Great thing : bindModel

At present moment a have a lot of free time for self improvement and I can learn CakePHP deeper and deeper, as it possible ;-)

In one of my project I have two table with simple relation

Division (id, title) - hasMany Staff
Staff (id, division_id, name, jobtitle..)

So. Now I need to get some info like: I need to get all Staff where birthday today, and get result like:
Array (
   [0] => ["Division"] = Array ...
         => ["Staff"] = [0]
  [1] ...

But I don't want (or cann't) rewrite model fore staff/division. So, What I must doing?

Of cause I must to use this wonderful thing - bindModel ;-)

Look

$this->Division->bindModel(array("hasMany" => array ("Staff" => array (
"conditions" => array ("MONTH (birthday) = " . $month, "DAY (birthday) = " . $day),
"fields" => array ("Staff.id,Staff.name"),
"order" => array("Staff.name" => "ASC")))));
$staff = $this->Division->find("all");

Also, we can put in field "fields" something like this
"fields" => array ("COUNT (Staff.id) as count")

And we have array with Division and numbers (count of staff with correct birthday)

Simple? yep. And in good cakephp tradition ;-)

Labels: , , ,

Friday, February 01, 2008

Visualize your models

The article by Cakeexplorer on a script to build an image of your db schema. I had been meaning to write such a script for some time, it was great to have it already ticked off the to-do list.

More information here.

Labels: , ,

Tuesday, December 04, 2007

Multiple rules of validation per field in CakePHP 1.2

Custom Validation and Multiple rules of validation per field in CakePHP 1.2

It's really very useful information! A lot of time I thinking about: how to check size of field, NOT_EMPTY or something else.

And now, at Bakery, I found articles: How to made custom validations ;-)

Look here and use this great tip! Link

Labels: , , ,