Jump to:

7940 Posts in 1543 Topics by 946 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, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 2031 Views
  • vancouverWill
    Avatar
    Community Member
    121 Posts

    Creating pages automaticaly from a DataObjectSet with one page per dataObject Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Creating pages automaticaly from a DataObjectSet with one page per dataObject Link to this post

    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

  • vancouverWill
    Avatar
    Community Member
    121 Posts

    Re: Creating pages automaticaly from a DataObjectSet with one page per dataObject Link to this post

    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.

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Creating pages automaticaly from a DataObjectSet with one page per dataObject Link to this post

    Hi.

    You have to use: OtherID (case-sensitive). Something like this should work:

    $otherID = Director::urlParam('OtherID');

    Yay, Post 404

  • vancouverWill
    Avatar
    Community Member
    121 Posts

    Re: Creating pages automaticaly from a DataObjectSet with one page per dataObject Link to this post

    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

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Creating pages automaticaly from a DataObjectSet with one page per dataObject Link to this post

    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_rules

    The one that is used by default for controllers is this one:

    '$Controller/$Action/$ID/$OtherID' => '*'

  • UncleCheese
    Avatar
    4085 Posts

    Re: Creating pages automaticaly from a DataObjectSet with one page per dataObject Link to this post

    Hasn't that been superseded by the $url_handers array?

  • vancouverWill
    Avatar
    Community Member
    121 Posts

    Re: Creating pages automaticaly from a DataObjectSet with one page per dataObject Link to this post

    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.

    2031 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.