Jump to:

23486 Posts in 18995 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Query Data from a custom Table

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1 2 3 4
Go to End
Author Topic: 4197 Views
  • slamby
    Avatar
    Community Member
    21 Posts

    Re: Query Data from a custom Table Link to this post

    You'll get it.

    Think about your Location object. It is empty for the moment. No definitions.

    Think about, what should be your detail page? Where should you define your detail page?
    The link must be empty. Where should it point to?

    Like you declared:
    allowed_children = Location
    But Location is empty, no definition.

    Tell me your conclusions.

  • Breastfed
    Avatar
    Community Member
    44 Posts

    Re: Query Data from a custom Table Link to this post

    I wish i could tell you my conclusion. I don't know where to go and what to do.

    Would be very nice if you could help me out on the Link Problem and what to put into the Location.php

    Thank you.

  • slamby
    Avatar
    Community Member
    21 Posts

    Re: Query Data from a custom Table Link to this post

    I took a look at your site.
    When I get you right, you like to show more details about what another user entered before in that form.

    So your Location and LocationSubmission are the same. You only want to show part of the submitted data in the overview and with the more link you like to take the user to all details of the same recordset.

    To get the more link working, it needs to point to an existing page. So you have to create a new page and a template for it. In the controller you need to grab the data from the database you like to show there again.

  • Breastfed
    Avatar
    Community Member
    44 Posts

    Re: Query Data from a custom Table Link to this post

    Hello Slamby,

    you are right, yes.

    I am sorry that it took so long to describe that stuff.

    i created a Page "Location" or Better the Detailpage "Location".

    There are 2 Questions now.

    1. How should the link look like which points from the Overview to the Detailpage?
    I would try it with: <a href="location/$ID">more</a>

    2. As you said i need in the Controller of the Detailpage a DataObject to grab the Right Data from the Database.
    Could you give me a Example how to achieve this?

    I am very thankful for your help so far.

    Thanks.

  • Breastfed
    Avatar
    Community Member
    44 Posts

    Re: Query Data from a custom Table Link to this post

    Slamby - could you help me here ?

    I am totally lost - i am searching in the Docs but i can't find anything.
    Would be very very helpful if you could give me some ideas how to create the more link and how to grab the data.

    Thanks.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Query Data from a custom Table Link to this post

    Hi Breastfed

    I think I uderstand what your are trying to do now

    The problem you have is that your LocationSubmission is not a page, it is a dataobject table, so it does not have a link. You have the right idea with Location, but your implementations is slightly wrong. What you need the Location page to do is display the details from your LocationSubmission table by retrieving the appropriate row via the ID, which you can pass through the URL as a URL parameter.

    So in your Location_Controller you need a funtion like this:

    public function GetLocationSubmission(){

    $Params = Director::urlParams(); //This gets our URLparams
    $SubmissionID = $Params['Action']; //gets the ID from our $Params array

    return DataObject::get_by_id("LocationSubmission", "$SubmissionID");

    }

    So now Location.ss will act as your tempalte to view a LocationSubmission, so you will add something liek this:

    <% control GetLocationSubmission %>
    $Name
    $Author
    $Email
    $Location
    etc. etc.
    <% end_control %>

    Now all you need to do is pass the correct ID for the locationSubmission you wish to show as I think you were trying to do before. So the link on your LocationHolder will look something like this: location/$ID

    Hope that finally gets you somewhere

  • Breastfed
    Avatar
    Community Member
    44 Posts

    Re: Query Data from a custom Table Link to this post

    aaaaah!!!

    Aram - thank you - it works now!

    Peeeewwww... thank so much!

    The LocationSubmission.php creates the Table for the Submissions, i have that structure from the Poll Tutorial.

    How can i correct the stucture when i have to create a Table, create a Page with a Submit Form, a Holder Page and a detail Page?

    This sitaution will be in my Projekt 2 more times, but i want to build i correct.

    Thanks and many Thanks.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Query Data from a custom Table Link to this post

    Well I think this is actually the correct way to do it, just using Location.ss as your template, it saves having to have a page in the CMS for each submission.

    So I think if you jsut do it like this then you should be fine

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