I would like generate list like day=>title:
$news = $this->News->find('list', array(
'conditions' => array(
'News.created LIKE' => '2008-09%'),
'fields' => array(
'DAY(News.created) AS day',
'News.name'),
'recursive' => -1));
...but doesn't work, why?
Function SUBSTR/SUBSTRING also...
When I use find with 'all' property, the function DAY works good!
It won't work because DAY(News.created)
is a computed value, but it will probably work if you make it a virtual field.
Note that when you use 'all'
, each row on the results array will have a [0][day]
key for that value, instead of [News][day]
. This means Cake won't recognize it as a field from model News
, and that's why you can't use it with 'list'
.