I've come across this question before in one of my projects, here's
what I worked out:
The reason the info is not present in the returned array is because
cake check if the field name is present in the model's metadata - i.e.
columns in the table.
Ways to get around this:
* Use afterFind to perform the operations in PHP (like you did)
instead of in the SQL
* Use afterFind to move the results into the array: (I did something
like this, but in a behavior)
function afterFind($results) {
foreach ($results as $key => $row) {
if (!empty($row[0]['validity_date_fmt'])) {
$results[$key]['Event']['validity_date_fmt'] = $row[0]
['validity_date_fmt'];
unset($results[$key][0]['validity_date_fmt']);
}
}
return $results;
}
* Override the Event::loadInfo() function to tack on another field
called 'validity_date_fmt' (NOT tested)
> This might cause problems when doing a query with no specified
fields, as it will try to grab the 'validity_date_fmt' from the
database,
where it doesn't exist. You'd have to write a beforeFind handler
to check for this condition - or something
Hope this helps; in any case I'd like to see the "official" way to
handle this issue.
On 31 Jul, 19:55, keys71 <[EMAIL PROTECTED]> wrote:
> ...or is the usage of an 'afterFind' - function the right method of
> resolution (because it works)?
>
> function afterFind($results) {
> foreach ($results as $key => $val) {
> if ( isset($val['Event']['validity_date']) ) {
> $dates = explode("-", $val['Event']['validity_date']);
> $results[$key]['Event']['validity_date_fmt'] =
> $dates[2].".".$dates[1].".".$dates[0];
> }
> }
> return $results;
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---