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

Query Data from a custom Table


Go to End
Reply


30 Posts   4473 Views

Avatar
Breastfed

Community Member, 44 Posts

9 March 2009 at 3:04am

Hello

how can i retreive all Entries of a Custom Table?
I set up a table "LocationSubmission" and i can insert it with a form, but i dont know how to start the ouput on a LocationHolder.

Anybody with a basic (!) Tutorial?

Thanks!

Avatar
Breastfed

Community Member, 44 Posts

9 March 2009 at 7:25am

Ok i got it running now, but maybe somebody can help me now with the following:

I have a LocationHolder for all Locations and a Location (Pagetype) for the Detailview.

How can i link from the Holder with a <a>Tag to the Location and get the Pagedetails there?

Avatar
Sam

Administrator, 685 Posts

9 March 2009 at 11:18am

you should juts be able to use this:

DataObject::get("LocationSubmission")

if you make a method on your controller like thisÚ

function Submissions() {
return DataObject::get("LocationSubmission");
}

Then you can have a <% control Submissions %> entry in your template:

<ul>
<% control Submissions %>
<li><a href="$Link">$Title</a></li>
<% end_control %>
</ul>

$Link and $Title will be taken from each LocationSubmission object and inserted into the repeating <% control %> ... <% end_control %> block in the template.

Avatar
Breastfed

Community Member, 44 Posts

9 March 2009 at 8:36pm

Hi Sam,

thanks for answering.
Everything is working except the Link to a detailed Page.

When i am inserting the $Link it will give me nothing back.

As i know it from other PHP Applications i should be able to link to the detailed Page and add an ID or Name to $_GET it from the Database, maybe you can explain how to get the Link going and how to receive Data on the detailed Page.

Would be very thankful!

Avatar
Breastfed

Community Member, 44 Posts

12 March 2009 at 11:09am

Somebody who might help me here?

On the HolderPage i got an Overview of ALL Locations inerted in the DataTable.

By control in can create the Loop.

But now i want to go to the detailed Page with more Infos about the Location.
So i tought to create the following Anchor tage

   <a href="kicker-location/$ID">mehr</a>

The Page "kicker-location" is the Detailpage.

On the Holder i have this DataObejct:

      function LocationShow ()
      {
         $sort = 'Created DESC';
         
         $data = DataObject::get('LocationSubmission','',$sort,'','');
         return $data;
      }
   

How can i retrieve Data on the DetailPage now by editing the DataObject?

Would be very happy about Help.

Thanks!

Avatar
Breastfed

Community Member, 44 Posts

12 March 2009 at 10:10pm

Sorry - but i am stuck now - would be so glad for Information.

Avatar
Carbon Crayon

Community Member, 598 Posts

12 March 2009 at 11:39pm

Edited: 12/03/2009 11:40pm

Hi

This works just as sam described using the $Link variable. You can't use IDs as links or anything else, you need to use the variable that is provided. You should only need one Location holder and make all the locations children of this page.

In your LocationHolder controller you need a function like this:

function GetLocations()
{
return DataObject::get('Location', 'ParentID = {$this->ID}', 'ID DESC');
}

This will return all the locations which are children of this page and order them by their ID (essentailly the same as ordering by created as IDs are auto incremented)

Then in your template:

<% GetLocations %>
<a href="$Link" >$Title</a>
<% end_control %>

If there is nothing in the href then check that you have $Link with a capital L.

Avatar
Breastfed

Community Member, 44 Posts

13 March 2009 at 1:05am

Hello Aram,

this is My LocationHolder.php

<?php
   class LocationHolder extends Page {
      
      static $allowed_children = array(
         'Location'
      );
      
      function LocationShow ()
      {
         $sort = 'Created DESC';
         
         $data = DataObject::get('LocationSubmission','',$sort,'','');
         return $data;
      }
      
      function GetLocations()
      {
         return DataObject::get('Location', 'ParentID = {$this->ID}', 'ID DESC');
      }
   
   }
   
   class LocationHolder_Controller extends Page_Controller {
   

   
   }
   

?>

and this is the LocationHolder.ss

<div id="col1">
<% include SideBar %>
</div>
<div id="col2">
<h2>Locations</h2>

<% control LocationShow %>
<!-- Location Row -->
<% if Odd %>
<div style="margin-bottom: 10px; padding-bottom: 5px; border-bottom: 1px dotted #000;">
<% else %>
<div style="margin-bottom: 10px; padding-bottom: 5px; border-bottom: 1px dotted #000; background-color: #eaeaea;">
<% end_if %>
   $ID <br />
   $Name
   $Description
   $Adress
   $PLZ
   <a href="$Link">mehr</a>

</div>
<!-- end: Location Row -->
<% end_control %>

</div>

<div id="col3">
</div>

But the output of $Link is just empty.

Sorry - could you help me?

Go to Top