3060 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 981 Views |
-
Get element by DataObject::get ?

7 June 2010 at 8:06pm Last edited: 7 June 2010 8:41pm
hi
simple problem
how to get title from DataObject::get ?function a() {
$x = DataObject::get("SiteTree");
return $x->Title;
}
doesnt workEDIT:
function a() {
$x = DataObject::get("SiteTree");
foreach($x as $y) {
echo '<p>' . $y->Title . ' ' . $y->URLSegment . '</p>';
}
} -
Re: Get element by DataObject::get ?

8 June 2010 at 10:03pm
Explaination - DataObject::get returns a set. When you have a set of objects you can't call methods, fields on the set since they exist on the objects in the set and not the set itself.
DataObject::get('SiteTree'); - returns a set of all SiteTree objects (pages)
DataObject::get_one('SiteTree'); - returns a object - the first SiteTree object
DataObject::get_by_id('SiteTree', $id); - returns a object - the SiteTree object with the ID = $id;Hope that helps.
| 981 Views | ||
|
Page:
1
|
Go to Top |


