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.

Data Model Questions

DataObject PAge

Go to End

15 Posts   4757 Views


18 February 2009 at 11:47pm Community Member, 63 Posts

Hi, I have read and understood the dataobject tutorials and how to display them on a page

what I would like now is to create a unique page for each dataobject row. Is this possible and how ?




24 February 2009 at 11:35am Community Member, 604 Posts


I don't quite follow what you're trying to do here. Can you be a bit mroe detailed?



25 February 2009 at 6:41am (Last edited: 25 February 2009 6:58am), Community Member, 63 Posts

Ron, I was enquiring about dataobjects : I know how to display a list of records on a page, but I don't know how to create a unique url for each record of a databobject


25 February 2009 at 8:08am 4085 Posts

If the DataObject needs a URLSegment, it needs to be a Page, not a DataObject..

I think you're misunderstanding something.. ?


25 February 2009 at 3:53pm Forum Moderator, 5511 Posts

but I don't know how to create a unique url for each record of a databobject

The forum module does something like this, You need to have 'Holder' page though. Eg a forum thread isnt a page in the site but by using the ID of the thread in the url and a function 'show' or something you can show your dataobject.

So if its not a page object you can do something like this in your controller class (mysite/code/page.php). It could be called anything

function view() {
if($id = Director::urlParam('ID')) { // check to see we have been passed an ID
return DataObject::get_by_id("SomeDataObject", $id);

In the template you could do $view.Title or $view.Date to access the information in the DataObject.

Then you would have the url like to view the 12th dataobject. Thats just a basic example which is easily expanded (eg if that object doesn't exist)


15 July 2009 at 7:50am Community Member, 131 Posts

Hi, this is exactly what I was looking for, however I can't get it working.
First I did what willr wrote in his post and added this to PersonsPage.php:

class PersonsPage_Controller extends Page_Controller {
   function view(){
      if($id = Director::urlParam('ID')){
      return DataObject::get_by_id("PersonsObject", $id);

That returned a "Page not found" and no signs of my

So I did some research in the forum-module, and added the following lines to PersonsObject.php:

function Link() {
   return "show/" . $this->ID;

Right now I can call $Link in instead of fx a hardcoded localhost/myss/show/1
That's nice, but I still get no signs of my (and still the same "Page not found"-message.

Does someone have any suggestions?


15 July 2009 at 8:02am 4085 Posts

You need a url segment first so SS knows which controller to use.


16 July 2009 at 12:53am (Last edited: 16 July 2009 1:02am), Community Member, 131 Posts

yeah, that makes sense.

But now I stumble upon two other learning-opportunities (problems don't exist, do they?):

1: how do I retrieve the URLSegment dynamically?

adding $this->PersonsPages()->URLSegment or $this->URLSegment to the function Link() rendered

In the forummodule the following string is used: $this->Forum()->Link(), however that gives an error: Uncaught Exception: Object->__call(): the method 'link' does not exist on 'ComponentSet'. Because the error didn't occur on the forummodule, I searched in the module for another place where a method Link() is defined, but couldn't find it.

2: hardcoding the urlsegment ( renders a white screen (nothing on it and no firebug-errors). I checked the templates and there is a template with content in the mysite/template/Layout-folder so that shouldn't be the cause (I also tried moving it to mysite/template or renaming it to (as is done in the forum-module) but that didn't work either)

BTW, I found some errors in my original code, so I'll post a better version here:

class PersonsPage_Controller extends Page_Controller {
      function view($id = null) {
      if($id == null)
         $id = $this->urlParams['ID'];
      if($id && is_numeric($id))
         return DataObject::get_by_id("PersonsObject", $id);

Go to Top