Jump to:

23369 Posts in 18145 Topics by 2863 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: 4110 Views
  • Aram
    Avatar
    Community Member
    598 Posts

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

    what is 'LocationSubmission' ? I don't think it is a page? If it's not a page then it can't have a link. Try replacing the <% control ShowLocation %> with the the function I suggested so <% control GetLocations %>. This will return the child pages which are of 'Location' type so if you wanted each location to be listed then you need to make a page for each.

    I think you are getting confused with what is and what isn't a page. If you want LocationSubmission to have a link it needs to have it's own LocationSubmission.php with a model and a controller extending Page and Page_Controller respectively. It also needs a template file LocationSubmission.ss.

    Have a look through the tutorials to see how all this stuff works. http://doc.silverstripe.org/doku.php

  • Breastfed
    Avatar
    Community Member
    44 Posts

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

    Hello Aram,

    i am trying to deal with the Docs the whole time, but now i am stuck.

    Let me Explain what i have now.

    The LocationSubmission is:
    The Page where i submit my Locations on the Frontend, they are saved into the DB.
    Files are created: LocationSubmission.php and ...ss

    The Page Locations:
    This is the Holder Page, where ALL Locations are listed, but only an Overview.
    with a Link i want to go deeper to the DetailPage wich is "Location".

    The Pages "Locations" and "Location eintragen" are created with the CMS.

    You can see the Pages here:

    "Mehr" is more for the Link to the Details.

    Am i better in my Description now?

  • slamby
    Avatar
    Community Member
    21 Posts

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

    Tell us, what do you mean by "custom" table?
    Is it build without using silverstripe's database builder tool?

  • Breastfed
    Avatar
    Community Member
    44 Posts

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

    I Created the Table with PHP File within "mysite/code" to store the Forminserts.

  • slamby
    Avatar
    Community Member
    21 Posts

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

    Sorry, I do not understand the meaning of your words.
    Please post the content of that file.

  • Breastfed
    Avatar
    Community Member
    44 Posts

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

    <?php
       class LocationSubmission extends DataObject {
          static $db = array(
             'Name' => 'Varchar(200)',
             'Author' => 'Varchar(100)',
             'Email' => 'Varchar (100)',
             'Description' => 'Text',
             'Adress' => 'Varchar(150)',
             'PLZ' => 'Int(5)',
             'Location' => 'Varchar(50)',
             'Country' => 'Varchar(50)',
             'Table' => 'Varchar(150)'

          );
       }

       
    ?>

    And the FolderStructure attached as an Image.

    Thank you.

    Attached Files
  • slamby
    Avatar
    Community Member
    21 Posts

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

    What you are doing there is defining an object with the attributes it will have and where to store them.
    Now you can get each attribute in your view like you did with:
    <% control LocationShow %>
    ....
    $Name
    $Description
    $Adress
    $PLZ

    <% end_control %>

    This calls the method LocationShow of your LocationHolder class.

    LocationHolder per Definition is the Holder for the children.

    You defined the children using:
    static $allowed_children = array(
    'Location'
    );
    in you LocationHolder class.

    This means objects of type Location will be stored in the Holder class.

    Tell me, what does your definition for the Location object look like?
    Please post the code.

  • Breastfed
    Avatar
    Community Member
    44 Posts

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

    Currently the Location.php ist empty or has just this one:

    <?php

       class Location extends Page {
       
       
       }

       
       class Location_Controller extends Page_Controller {
       

       
       }

    ?>

    BUT - the $Link in the LocationHolder.ss is empty.
    I dont get it.

    4110 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.