3070 Posts in 869 Topics by 651 members
| Go to End | Next > | |
| Author | Topic: | 874 Views |
-
Fetch multiples classe with DataObject::get

10 November 2011 at 5:16am
Hi all,
is it somehow possible to fetch more than one class with DataObject::get or can i add the result of one DataObejct to another? I am trying to adapt the MenuItem class from the MenuManager Module to fetch more than the standard page class.TIA Tom
-
Re: Fetch multiples classe with DataObject::get

10 November 2011 at 6:50am
All DataObject::get requests are returned as a DataObjectSet, so you could use $dataobjectset->merge($yourotherdataobjectset)
This will combine different sets into one.
-
Re: Fetch multiples classe with DataObject::get

10 November 2011 at 8:36pm
This works. Thanks Ryan.
One more question if i may.
What i am doing now is fetching a pagetypes and merging them - all 'manually'.Is there a function to return the different page type? I'd like to use this result to loop the merging. New page type will than be added 'automatically' to the merging process.
Thanks again, Tom
-
Re: Fetch multiples classe with DataObject::get

10 November 2011 at 9:06pm
If all your different page types extend from a Page class something like this might work? Untested
$Pages = DataObject::get('Page', 'ClassName = 'BlogPage' OR ClassName = 'GalleryPage'); etc.
-
Re: Fetch multiples classe with DataObject::get

10 November 2011 at 9:13pm
Not sure what you mean by "New page type will than be added 'automatically' to the merging process" - if all you want is to get every type of page there is then DataObject::get('Page'); or DataObject::get('SiteTree'); shold do it
-
Re: Fetch multiples classe with DataObject::get

10 November 2011 at 11:17pm
All my types extend SiteTree.
I already tried the query with DataObeject::get(Class1, Class2,...) and got an error message.
With a SiteTree query i might get all valid (non-unique) ClassNames.
To make them unique i would probably just have to figure out the right DataObject::get statement.
With the unique ClassNames i could loop to get all DataObjects and merge them - if i knew how to...
...hope this makes things more understandable... -
Re: Fetch multiples classe with DataObject::get

10 November 2011 at 11:35pm
I still don't quite get what you're after - but can you try something like
$Pages = DataObject::get("SiteTree", "ClassName = 'Class1' OR ClassName = 'Class2");
This means your asking for SiteTree objects with a $where statement that's saying 'of these classes only'.
What are you trying to achieve exactly though in real-world terms? If you want a DataObjectSet of every page in your website I think simply doing DataObject::get("SiteTree") should give you that.
-
Re: Fetch multiples classe with DataObject::get

10 November 2011 at 11:53pm
I am trying to adapt the MenuItem.php class from the menumanager module.
This code:
public function getCMSFields() {
$pages = DataObject::get('Page');
if ($pages) {
$pages = $pages->toDropdownMap('ID', 'Title', '(Select one)', true);
}
works for the standard page class.
What i did is this:
$pages = DataObject::get('Page');
$myClass = DataObject::get('MyClass');
... more classes
$pages->merge($myClass)
...more mergesThis works but i want the function to automatically add all relevant classes to the dropdown.
| 874 Views | ||
| Go to Top | Next > |



