I may be out of line here, but why would you want this if Cake already lets
you access it via indexed arrays?
Anyway one thing I can think of is add the following method to your
AppController:
function toObject($array)
{
$result =& new stdClass;
foreach($array as $index => $value)
{
if (!is_numeric($index) && is_array($value))
{
$result->$index = $this->toObject($value);
}
else if (!is_numeric($index))
{
$result->$index = $value;
}
}
return $result;
}
And then on your controller change the code to:
function listof()
{
$records = $this->Post->findAll();
if ($records !== false)
{
foreach($records as $index => $record)
{
$records[$index] = $this->toObject($record['Post']);
}
}
$this->set('posts', $records);
}
I haven't tested this, so try it out.
-MI
---------------------------------------------------------------------------
Remember, smart coders answer ten questions for every question they ask.
So be smart, be cool, and share your knowledge.
BAKE ON!
-----Mensaje original-----
De: [email protected] [mailto:[EMAIL PROTECTED] En nombre
de Ananda Putra
Enviado el: Viernes, 15 de Diciembre de 2006 06:25 a.m.
Para: [email protected]
Asunto: How to make findAll() return object?
How to make findAll() return object?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---