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


Reply

30 Posts   4231 Views

Avatar
Carbon Crayon

13 March 2009 at 1:16am Community Member, 598 Posts

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

Avatar
Breastfed

13 March 2009 at 1:39am Community Member, 44 Posts

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:

www.aerofunk.de/silverstripe/locations

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

Am i better in my Description now? :)

Avatar
slamby

13 March 2009 at 6:52am Community Member, 21 Posts

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

Avatar
Breastfed

13 March 2009 at 7:41am Community Member, 44 Posts

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

Avatar
slamby

13 March 2009 at 8:04am Community Member, 21 Posts

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

Avatar
Breastfed

13 March 2009 at 8:06am Community Member, 44 Posts

<?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
Avatar
slamby

13 March 2009 at 8:31am Community Member, 21 Posts

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.

Avatar
Breastfed

13 March 2009 at 8:37am Community Member, 44 Posts

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. :(