7911 Posts in 1354 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Creating pages automaticaly from a DataObjectSet with one page per dataObject
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | Next > | |
| Author | Topic: | 1718 Views |
-
Creating pages automaticaly from a DataObjectSet with one page per dataObject

28 August 2009 at 11:11am
How did you manage to get ImageGallery to generate pages from the DataObjectSet and it's own Urls's for the albums. I can see the line where the links are being created with
public function Link()
{
return $this->ImageGalleryPage()->Link('album/'.$this->Folder()->Name);
}The thing I don't understand is how silverstripe recognizes this information and knows where to go.
I want to do a similar thing to what you are doing. Have a data page with lots of entries and then click on an object to take it to a pregenerated page showing the information for that object only. So when you are in the cms you only have one page in the left navigation and adding extra data is just done from the tabs. Then on the front end I can list the onjects in a page and link through to them for more info.
Thanks for the help
Will
-
Re: Creating pages automaticaly from a DataObjectSet with one page per dataObject

28 August 2009 at 1:26pm
Dynamic Pages are fairly simple. See the link to the page
return $this->ImageGalleryPage()->Link('album/'.$this->Folder()->Name); outputs a link like site.com/gallery/album/my-photos
URLs in SS can be read like /Controller/Action/ID so that above URL translates to calling the album() method on the Controller for the page with the URLSegment 'gallery' which in this case is the 'GalleryPage_Controller'.
So if you look at GalleryPage.php at the GalleryPage_Controller you will see a function album() which outputs the page content for the 'my-photos' album. You can see more detail my looking at that method. You can also define a separate template for the album page. Normally you would have a GalleryPage.ss template but with the 'album' action you can make a GalleryPage_album.ss template to style it differently
-
Re: Creating pages automaticaly from a DataObjectSet with one page per dataObject

28 August 2009 at 4:37pm
Thanks for the quick reply. I read around some topics as well on the url method. I got it working as you said with /Controller/Action/ID and I can see the objects in my data set. How about if I want to do /Controller/Action/ID/$otherId? I tried that and the page would load up I could extract $ID still but I couldn't get read $otheID. Any idea why that would be? I have looked all over and haven't seen any examples of second level URL inputs. Thanks again for the quick reply.
-
Re: Creating pages automaticaly from a DataObjectSet with one page per dataObject

28 August 2009 at 6:33pm Last edited: 28 August 2009 6:34pm
Hi.
You have to use: OtherID (case-sensitive). Something like this should work:
$otherID = Director::urlParam('OtherID');
Yay, Post 404
-
Re: Creating pages automaticaly from a DataObjectSet with one page per dataObject

29 August 2009 at 5:21am
Perfect that is exactly what I needed. Worked straight away. Can it be extended to use other variables? So $id/$otherID/$thirdID/$fourthID
Has anyone done anything like that.
Thanks
-
Re: Creating pages automaticaly from a DataObjectSet with one page per dataObject

29 August 2009 at 5:30am
Yeah, you can create arbitrary URL actions/parameters. They are called rewrite rules (not to be confused with mod_rewrite rules) and can be placed in your mysite/_config.php file. Look here for details:
http://doc.silverstripe.com/doku.php?id=director#custom_rewrite_rulesThe one that is used by default for controllers is this one:
'$Controller/$Action/$ID/$OtherID' => '*'
-
Re: Creating pages automaticaly from a DataObjectSet with one page per dataObject

29 August 2009 at 5:46am
Hasn't that been superseded by the $url_handers array?
-
Re: Creating pages automaticaly from a DataObjectSet with one page per dataObject

2 September 2009 at 12:46pm
Thanks again
I tried to edit
// sapphire/main.php
Director::addRules(1, array(
'$URLSegment/$Action/$ID/$OtherID' => 'ModelAsController',
));to
Director::addRules(1, array(
'$URLSegment/$Action/$ID/$OtherID/$thirdId' => 'ModelAsController',
));in //sapphire/main.php as well as in mysite/_config.php and both times nothing happened and I thought there was no errors but when I tried to put a third variable into mysite then I got the problem
I can't handle sub-URLs of a WebsitePage_Controller object.
any idea why this could be, I checked the error log and couldn't find any more information.
Thanks
Will
I can't handle sub-URLs of a WebsitePage_Controller object.
| 1718 Views | ||
| Go to Top | Next > |



