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 ?
Thanks
E.
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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, 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 ?
Thanks
E.
Hiya,
I don't quite follow what you're trying to do here. Can you be a bit mroe detailed?
Cheers
Aaron
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
If the DataObject needs a URLSegment, it needs to be a Page, not a DataObject..
I think you're misunderstanding something.. ?
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 yoursite.com/home/view/12 to view the 12th dataobject. Thats just a basic example which is easily expanded (eg if that object doesn't exist)
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);
}
}
}
So I did some research in the forum-module, and added the following lines to PersonsObject.php:
function Link() {
return "show/" . $this->ID;
}
Does someone have any suggestions?
You need a url segment first so SS knows which controller to use.
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 http://www.mysite.com/view/123.
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 (http://www.mysite.com/the-persons-page-you-want-to-view/view/123) renders a white screen (nothing on it and no firebug-errors). I checked the templates and there is a PersonsObject.ss 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 PersonsPage-view.ss (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);
}