Reputation: 431
I am new to silverstripe framework and trying to fetch a list of menu in the admin panel.
I found lots of example to show menu on front-end by Menu(1) and Menu(2) etc. but did not get any sample code to fetch same menu array in admin model.
The code I tried is:
public function getCMSfields() {
$fields = FieldList::create(TabSet::create('Root'));
$fields->addFieldsToTab('Root.Main', array(
TextField::create('Name'),
DropdownField::create('URL')
->setSource(SiteTree::get()),
));
return $fields;
}
Upvotes: 1
Views: 251
Reputation: 3318
There is also (albiet for an older version) this tutorial http://www.ssbits.com/tutorials/2010/dataobjects-as-pages-part-2-using-model-admin-and-url-segments-to-create-a-product-catalogue/ from ssbits
Upvotes: 0
Reputation: 1199
ModelAdmin is mainly there to manage DataObjects and not Pages. Have a look at the Docs and this Lesson to learn more about ModelAdmin.
But if you want to manage pages in a ModelAdmin, you could do it like that
class MyPageAdmin extends ModelAdmin {
...
...
private static $managed_models = array(
'Page'
);
public function getList() {
$list = parent::getList();
if($this->modelClass == 'Page'){
$list = $list->filter('ParentID', '1');
}
return $list;
}
}
To manage only children from a specific page, use the getList() function and filter your list after your needs.
Upvotes: 1