Jump to:

23483 Posts in 18976 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Displaying data from database 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
Go to End
Author Topic: 2511 Views
  • Ronin
    Avatar
    Community Member
    50 Posts

    Displaying data from database table Link to this post

    I'm feeling somewhat stupid at the moment. I have been through the tutorials and done all 5 of them and have not been able to work out how to dispaly data from a table. I want to simply display data from a table that I have successfully created in the data base. This is a simple table with 3 columns in it. All I want to do is display the data from one or more of these columns on each page of my site. I just want the most basic way of doing this to start off.

    Some help on the basic syntax would be much appreciated.

  • joshy
    Avatar
    Community Member
    57 Posts

    Re: Displaying data from database table Link to this post

    In the controller (php):

    public function MyThing()
    {
    return DataObject::get("TableName");
    }

    In the template:

    <ul>
    <% control MyThing %>
    <li>This is the Title: $Title</li>
    <% end_control %>
    </ul>

    I suggest you re-read the tutorials more carefully because they're very good!

  • Ronin
    Avatar
    Community Member
    50 Posts

    Re: Displaying data from database table Link to this post

    Thanks for that. It was exactly what I needed. I agree that the tutorials are pretty good. However they are designed with a specific goal in mind ie whatever it is that they have said they are going to create. When you want to do something slightly different and you are not familiar with the fundamentals of how things work it can be extremely time consuming to work out what to do.

    Again thanks for your help I am now happy to work out how to do the more complex things which are my actual end goal.

  • joshy
    Avatar
    Community Member
    57 Posts

    Re: Displaying data from database table Link to this post

    I know what you mean.

    By the way, check out http://doc.silverstripe.org/doku.php?id=datamodel, which explains how to use DataObject a bit more.

    Have fun SilverStriping!

    Cheers,

    Josh

  • Bitburger
    Avatar
    Community Member
    1 Post

    Re: Displaying data from database table Link to this post

    Hi

    I guess I got stuck with the same as ronin. I tried the suggested solution but there is only one line appearing on my website, instead of showing all the approx 300 lines which are stored in the table.

    I made the tutorials 2 and 5 which are related to data handling, but as ronin already said, it is hard for a newbie like me to transfer some things from the tutorials to individual soluitions which may me much simpler but dont work.

    can somebody assist please?

    thank you very much in advance

    2511 Views
Page: 1
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.