Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

how to work with class ModelAdmin and Subsite?


Go to End


5 Posts   1218 Views

Avatar
VPull

Community Member, 58 Posts

12 May 2015 at 8:53pm

I have created DataObject and ModelAdmin class for Product as shown here http://doc.silverstripe.org/en/developer_guides/customising_the_admin_interface/modeladmin
which works fine in Main Site, but it is now showing in admin menu of Subsite.
How do I access same Product data for Subsite?

Avatar
Pyromanik

Community Member, 419 Posts

12 May 2015 at 9:03pm

If there is nothing provided (or an already existing addon), you will need to subclass ModelAdmin, then edit the list getter to filter on site ID.
Your objects will also of course need to be associated with a site (like pages do when you install subsites, normal data objects however do not).

Avatar
wmk

Community Member, 87 Posts

12 May 2015 at 9:13pm

Edited: 12/05/2015 9:46pm

The solution is quite simple: you need to apply `SubsiteMenuExtension` to your ModelAdmin, e.g. in your config.yml:

MyModelAdminAdmin:
  extensions:
    - SubsiteMenuExtension

Avatar
VPull

Community Member, 58 Posts

12 May 2015 at 9:53pm

Thanks Pyromanik adn wmk for your support.
Second option is really better and easy. but instead of mention config.yml, I had write the code

MyModelAdmin::add_extension('SubsiteMenuExtension');

in _config.php and it works.

Avatar
Pyromanik

Community Member, 419 Posts

15 May 2015 at 12:24am

Edited: 15/05/2015 12:24am

After editing YML you must flush before changes will take effect :)