a find() usually returns an array or a list of ActiveRecords which are objects. only _find('first'...) retuns a single object.
so basically you iterate of the returned array in a foreach and access your 'column-values' like you would access any object-property.
$People = $this->find('all');
foreach ($People as $Person){
echo $Person->name;
}
what otherwise is a 'row' results in an instantiated ActiveRecord, one could say.
a find() usually returns an array or a list of ActiveRecords which are objects. only _find('first'...) retuns a single object.
so basically you iterate of the returned array in a foreach and access your 'column-values' like you would access any object-property.
$People = $this->find('all');
foreach ($People as $Person){
echo $Person->name;
}
what otherwise is a 'row' results in an instantiated ActiveRecord, one could say.
damn, our forum is broken.
you could
echo $Person;
print_r((string)$Person);
Hm.
An action like this, if you have built the booklink-tutorial
class BookController...
function dumpy()
{
$Book = $this->Book->find('first');
$this->renderText((string)$Book);
}
now
http://localhost/booklink/book/dumpy
prints a nicely formatted info.
Details for Book with id 1
Id
1
Title
first book
Description
my first book
Author
1
Published on
2007-11-15
renderText just renders the given string/text.
BookController...
function dump_more()
{
$Books = $this->Book->find('all');
$this->dump($Books);
}
ApplicationController...
function dump($objects)
{
$this->renderText(join('',$objects));
}
http://localhost/booklink/book/dump_more
you can actually change the ->toString() method to alter the output if you really like to. usually you would do this on your shared_model.
1 to 11 of 11