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


Reply


3 Posts   1118 Views

Avatar
santosmateo

Community Member, 11 Posts

3 September 2011 at 8:17am

hello

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

Avatar
santosmateo

Community Member, 11 Posts

3 September 2011 at 11:10am

This is the code:

barqTipoProyecto.php:

<?php

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;
}

}

cabecera.php:

<?php

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
}
}

cabecera.ss:

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

very thanks!

Avatar
santosmateo

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 page.ss I have a reference to a header in Layout (cabecera.ss), called with <% include cabecera.ss%>

I wish could get in cabecera.ss 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: [url]http://www.silverstripe.org/data-model-questions/show/12601[/url]

In cabecera.php I added inside the controller:

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

in cabecera.ss:

<% 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.