Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Display a DataObject on a new "own" page

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

Page: 1 2 3
Go to End
Author Topic: 7901 Views
  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Display a DataObject on a new "own" page Link to this post

    @timwjohn - I think it would be able to support more rules, you probably need to define your own rules though.

    // in your config
    Director::addRules(100, array(
       '$Controller/$Action/$ID/$OtherID/$NextID/$FurtherID/$AnotherID/$YetAnotherID' => '*'
    ));

    Ref: http://doc.silverstripe.org/doku.php?id=director

  • timwjohn
    Avatar
    Community Member
    98 Posts

    Re: Display a DataObject on a new "own" page Link to this post

    Really? Wow, SilverStripe never ceases to impress me. Thanks Willr.

  • LinseyM
    Avatar
    Community Member
    99 Posts

    Re: Display a DataObject on a new "own" page Link to this post

    Hi there,

    Had this all working perfectly in 2.3.X using this method: http://www.ssbits.com/using-silverstripe-url-parameters-to-display-dataobjects-on-a-page/

    But I copied the code into a 2.4 install and I'm having some problems. I am sure I've replicated it over properly.

    So on this page I list all of the dataobjects:

    http://www.mysite.co.uk/services/self-build-developments/home-types/

    And clicking "more info" for any one of the listings appends the URL with the object ID, like so:

    http://www.mysite.co.uk/services/self-build-developments/home-types/3

    However, instead of displaying the object data, I get page not found instead!

    I don't think I've missed anything obvious.

    If its any use I could post up the code? Am wondering if its something to do with the URLs in 2.4 but am stuck!

    Thanks guys.

  • edk
    Avatar
    Community Member
    39 Posts

    Re: Display a DataObject on a new "own" page Link to this post

    Uncanny timing...I was working with a DataObject Class that I wanted to use this method as well....

    Okay so it totally has to do with 2.4 and nested urls...the issue is two fold (at least the solution that I got to work).

    1. In the Page class you now should define allowed actions.

    static $allowed_actions = array(
             'actionName'
          );

    The catch here is that now your urls will have to have this defined action. You cannot just use the $ID b/c it is dynamic and you won't be able to define all those in the $allowed_actions array.

    2. Okay so you will have to tweak you code some to look for your action and the parameter now as well. Here is what I did.

    public function getIndividualDataObject(){
             
             if ($this->request->latestParam('Action')) {
                $parameter = $this->request->latestParam('ID');
                
                if ($parameter) {
                   $DataObjectID = Convert::raw2xml($parameter);
                   if($DataObjectID){
                      $DataObjectInfo = DataObject::get_by_id('DataObjectClassName', $DesignGuideID);
                   
                      return $DataObjectInfo;
                   }
                }
             }
       }

    Now lastly you will need to update your links that call your Single DataObjects to include the action that you added to your $allowed_actions. Example.

    {$Top.Link}actionName/{$ID}

    Hope this helps...

    - Ed

  • LinseyM
    Avatar
    Community Member
    99 Posts

    Re: Display a DataObject on a new "own" page Link to this post

    Thanks Ed! I don't 100% understand this, but i think I get the jist of it! I will have a go at that today.

    Fingers Xd.

    L

  • Enclave SSC
    Avatar
    Community Member
    31 Posts

    Re: Display a DataObject on a new "own" page Link to this post

    Having the same problem here. Linsey, did you get this to work. I tried Eds changes but no joy as yet. Still get a page not found in ss 2.4

    Update: I sorted this out by moving allowed_actions onto the controller. Silly me. - Thanks

  • LinseyM
    Avatar
    Community Member
    99 Posts

    Re: Display a DataObject on a new "own" page Link to this post

    can't get it to work - i am getting page not found - or sometimes an error, but thats deffo just because i am footering about with it!

    am still trying to puzzle it out - think i'm maybe just missing something obvious,

    let me know how you get on.

    Linsey

  • Enclave SSC
    Avatar
    Community Member
    31 Posts

    Re: Display a DataObject on a new "own" page Link to this post

    Hey Linsey

    I got it working. If you still stuck just paste me your code and I will help out.

    7901 Views
Page: 1 2 3
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.