Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

Displaying data from database table


Reply


5 Posts   2623 Views

Avatar
Ronin

Community Member, 50 Posts

5 August 2009 at 10:45am

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.

Avatar
joshy

Community Member, 57 Posts

6 August 2009 at 6:30am

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!

Avatar
Ronin

Community Member, 50 Posts

6 August 2009 at 11:39am

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.

Avatar
joshy

Community Member, 57 Posts

6 August 2009 at 6:34pm

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

Avatar
Bitburger

Community Member, 1 Post

19 August 2009 at 10:30pm

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