Jump to:

3430 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » menu items from database table

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 989 Views
  • santosmateo
    Avatar
    Community Member
    11 Posts

    menu items from database table Link to this post

    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

  • santosmateo
    Avatar
    Community Member
    11 Posts

    Re: menu items from database table Link to this post

    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!

  • santosmateo
    Avatar
    Community Member
    11 Posts

    Re: menu items from database table Link to this post

    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: http://www.silverstripe.org/data-model-questions/show/12601

    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.

    989 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.