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.

Data Model Questions /

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

Managing DateObjects within DateObjects


Go to End


1256 Views

Avatar
jondbaker

Community Member, 19 Posts

9 December 2009 at 2:04pm

I'd like to create a page that displays links organized by categories. The current structure I have setup is LinkCategoryHolder(the actual page), LinkCategory, and Link, whereas LinkCategory and Link are both extensions of DataObject. Ideally, what I'd like to do is be able to click the Links(LinkCategoryHolder.php) page in the CMS, and then add display the different LinkCategories as tabs under Content. When clicking a particular LinkCategory tab, it would bring up a table of Links, and also present the ability to add new ones via the popup interface.

For the templates, I would just set up a control for the different LinkCategories, and then a control for Links inside of that.

Is this possible in the way that I'm describing, or would it be more easier if I were to just extend ModelAdmin and create a new menu link? Or is there an even easier way? It makes more sense to include it under the content of the page, but this designer has hit a road block.

LinkCategoryHolder.php

<?php
class LinkCategoryHolder extends Page {
    static $singular_name = 'Link Category overview';
    static $plural_name = 'Link Category overviews';
    static $db = array(
        'Headline' => 'Text',
    );
    static $has_many = array(
        'LinkCategories' => 'LinkCategory'
    );
}
class LinkCategoryHolder_Controller extends Page_Controller {}
?>

LinkCategory.php

<?php
class LinkCategory extends DataObject {
    static $singular_name = 'Link Category';
    static $plural_name = 'Link Categories';
    static $db = array(
        'Category' => 'Text'
    );
    static $has_many = array(
        'Links' => 'Link'
    );
    static $has_one = array(
        'LinkCategoryHolder' => 'LinkCategoryHolder'
    );
}
?>

Link.php

<?php
class Link extends DataObject {
    static $db = array(
        'LinkURI' => 'Text',
        'LinkDisplayText' => 'Text'
    );
    static $singular_name = 'Link';
    static $plural_name = 'Links';
    static $has_one = array(
        'LinkCategory' => 'LinkCategory'
    );
}
?>