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.

Customising the CMS /

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

DataObject with a list/details page


Go to End


3 Posts   822 Views

Avatar
mi32dogs

Community Member, 75 Posts

16 April 2015 at 6:24am

Hi,

I have a DataObject with a list/details page very similar to the regions section in the one Ring lessons, the only thing I’m trying to change is the linking from the ID to the URL Segment

So I changed the link function to:

public function Link(){
    //return $this->EventsPage()->Link('details/'. $this->ID);
    return $this->EventsPage()->Link('details/'. $this->UrlSegment);
  }

And the details function to this

public function details(ss_HTTPRequest $request){
    //$event = Event::get()->byID($request->param('ID'));
    $event = Event::get()->filter(array('UrlSegment' => $request->param('ID')));
    
    if(!$event) {
      return $this->httpError(404, 'That region could not be found');
    }

    return array (
      'Event' => $event,
      'Title' => $event->Artist
    );
  }

If I do a debug I see that all the data is there the only difference is that if you use the get()->byID you will get a Database record, and if you use the get()->filter you get a datalist

Now how do I show the DataList Data in the template? I tried everything but I have no success.

Avatar
catcherdev

Community Member, 9 Posts

16 April 2015 at 7:24am

Edited: 16/04/2015 7:26am

If you want to continue working with a single record, use this:

$event = Event::get()->filter(array('UrlSegment' => $request->param('ID')))->first();

This will pick out the first match. Hopefully, your UrlSegments are enforced to be unique within your context.

Avatar
mi32dogs

Community Member, 75 Posts

16 April 2015 at 7:59am

Thank you catcherdev, this is perfect works like a charm