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!
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
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!
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?
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.
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!
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!
Sorry - but i am stuck now - would be so glad for Information.
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.
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?