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.

Data Model Questions /

menu items from database table

Go to End

3 Posts   1153 Views


Community Member, 11 Posts

3 September 2011 at 8:17am


I'm trying to create a menu whose items are data from a table.

but with "dataobject" I can not see the results on the Menu template, to see this menu on all pages.

The idea is that I have created a table with "tags" on each subpage of the main page to search for these subpages for their tags.

Any ideas?

thank you very much


Community Member, 11 Posts

3 September 2011 at 11:10am

This is the code:



class barqTipoProyecto extends DataObject {

    static $db = array( 
        'Tipo' => 'Text', 

    static $belongs_many_many = array( 
        'tipoProyecto' => 'barqProyecto' 
    function getCMSfields_forPopup() {
        $fields = new FieldSet();
        $fields->push( new TextField( 'Tipo' ) );
        return $fields;



class cabecera extends Page {}

class cabecera_Controller extends Page_Controller {

function TipoProyecto() { 
     return DataObject::get("barqTipoProyecto"); // the dataobject class where I want to get the data

      <% control TipoProyecto %>
            <li>$Tipo</li>  <!-- a row into barqtipoproyecto table. (in Windows server the table names are lowercase. -->
      <% end_control %>

very thanks!


Community Member, 11 Posts

6 September 2011 at 4:57am

hello again,

I keep trying but I can not read data: (

I will try to explain better:)

I just want to read data from a table from any template.

this is the idea: within I have a reference to a header in Layout (, called with <% include>

I wish could get in data from a table to use as menus.

This table is created inside a DataObject called "barqTipoProyecto" and only has a column called "Tipo"

As seen in 5 of the web tutorial and in this post:

In cabecera.php I added inside the controller:

tProyecto function () {
         return DataObject:: get ("barqTipoProyecto");


<% Control tProyecto%>
             $Tipo  // this is the only column inside the table, the table name is "barqtipoproyecto"
       <% End_control%>

barqTipoProyecto.php contains:

<? php

class barqTipoProyecto extends DataObject {

     static $ db = array (
         'Tipo' => 'Text',

     static $ belongs_many_many = array (
         'tipodelProyecto' => 'barqProyecto'
     getCMSfields_forPopup function () {
         $ fields = new Fieldset ();
         $ fields-> push (new TextField ('Type'));
         return $ fields;

please a help, I'm blocked , I'm starting in SilverStripe.

Thank you very much again.