Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » How to show a database table

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1779 Views
  • TuTToWeB
    Avatar
    Community Member
    10 Posts

    How to show a database table Link to this post

    Hello to everyone.
    I created those class

    class ProductorManager extends Page
    {
    static $db = array('Percentage'=>'float'
    );
    static $has_one = array('id_productor'=>'Member'
    );

    public function Productors()
    {
    return DataObject::get("ProductorManager ");
    }
    }

    class ProductorManager _Controller extends Page_Controller
    {
    }

    and i've the table setted up, but i cannot retrieve datas from them. i thinks function Productors() is correct, but something don't work.
    I want to show Percentage and the complete productor's name fetched by Member's tables

    I dont know if i want clear about the explaination.
    Thanks to everyone.

    VG

  • noizy
    Avatar
    Community Member
    25 Posts

    Re: How to show a database table Link to this post

    you probably want to put that function in the Page_Controller, for starters.

    what does your template code look like?

  • TuTToWeB
    Avatar
    Community Member
    10 Posts

    Re: How to show a database table Link to this post

    Template page look like in this way temporarily

    <div class="body">
    <h1>$Title</h1>
    <% include SideBar %>
    <div style="clear:left">

    <% if Productor %>
    <% control Productor %>
    $FirstName .<br />
    <% end_control %>
    <% else %>
    <div class="message">No productors found</div>
    <% end_if %>
    </div>
    </div>

    First I put Productors() inside the Controller Class, but didn't work.
    I want to show each productor's name and i don't know where i've made a mistake.

    thank you very much

  • TuTToWeB
    Avatar
    Community Member
    10 Posts

    Re: How to show a database table Link to this post

    I solved that problem using a DataObject-derivated class.

    class Produttori extends DataObject
    {
    static $db = array('Percentuale'=>'float');
    static $has_one = array('Produttore'=>'Member');
    }

    Thanks you

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