Свежайшие Пирожки от CakePHP по-русски

Полнейшее руководство CakePHP 1.2 на русском языке, горячие новости и полезные статьи

Пользовательские методы и свойства

While CakePHP’s model functions should get you where you need to go, don’t forget that model classes are just that: classes that allow you to write your own methods or define your own properties.

Any operation that handles the saving and fetching of data is best housed in your model classes. This concept is often referred to as the fat model.

Простой текст
  1. class Example extends AppModel {
  2. function getRecent() {
  3. $conditions = array(
  4. 'created BETWEEN (curdate() - interval 7 day) and (curdate() - interval 0 day))'
  5. );
  6. return $this->find('all', compact($conditions));
  7. }
  8. }

This getRecent() method can now be used within the controller.

Простой текст
  1. $recent = $this->Example->getRecent();