I've been getting my head around Silverstripe recently and have been finding it very well thought out and good to work with. I'm still learning to think the SS way, though, and I have a very simple requirement which is giving me pause for thought. I need to add a top level Links page, to which site administrators can add links consisting of a link title and a URL. My first instinct was to follow the model for News from tutorial 2 and have a LinkHolder page type with an '$allowed_children' array of LinkPage type pages. This allows me to present the site administrators with a form in the CMS containing fields for link title and URL, so they can add multiple subpages under the Links page. But something about this doesn't feel quite right. The LinkPage isn't actually a page in the normal sense - it's not something that an end user would click on to bring up the full page, unlike a News article - it's just a means to get the data into the system to be presented as a list. Of course, I can control all of this in the template file, but I'm wondering whether my general thinking is wrong at this point. Should I be thinking of a page as a unit whereby a site administrator can add information to the website (in which case I'm OK), or as something to be displayed and used in menus, searches, etc.?
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.
Hi
You're absolutely right. Things like links should not be represented as a separate page, they are Data-Objects. You should read tutorial 5, it covers this aspect of SilverStripe. As you will see in tutorial 5, there are also special controls (TableField classes) that allow you to modify the DataObjects of a page in the CMS.
For a more advanced control, have a look at the DataObjectManager module
Thanks a lot for pointing me in the right direction. I took a look at the DataObjectManager docs and the Testimonials example there was very close to what I needed to do with links. I feel I should go through the tutorial a couple of times until I really fully understand what's going on, but for the moment I'm just glad to have things working.
Actually, I haven't quite got things working. I'm stumped at the moment by a display issue, having sorted out how to to get the links data into the system. I now have a LinksPage page type, with a $has_many array of Link objects, and the CMS allows me to add these just fine. But when I switch to the draft site view and click the Links menu item, which should bring me up my page listing the links, I get a plain text page containing the single word 'LinksPage'. I've no idea where this is coming from and what it indicates is wrong. No errors show up in the Apache error log. Any suggestions?
That looks like a template issue to me. Do you have a Template for the LinksPage (must be named LinksPage.ss). Also make sure, that your LinksPage inherits from Page. Your LinksPage.php file should contain 2 classes:
class LinksPage extends Page {
// class implementation goes here
}
class LinksPage_Controller extends Page_Controller {
// controller class implementation goes here
}
If that doesn't work, I suggest you post your LinksPage code on http://pastebin.com (or similar) and provide us with the link to the code
Duh...I had missed out the controller class! This is what happens when I blindly copy and paste from the Testimonials example. Thanks for the help again. Stick around, I'm sure I'll need you again :)