Jump to:

3430 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » DayOfMonth not working in GroupedList

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

Page: 1
Go to End
Author Topic: 332 Views
  • quanto
    Avatar
    Community Member
    81 Posts

    DayOfMonth not working in GroupedList Link to this post

    Hi,

    I'm trying to format a date ($Datum) in a proper way, after grouping by Datum. However, it's not formatting (not .DayOfMonth, FormatI18N or .Year).

    My code:
    AgendaItem.php

    <?php
    class AgendaItem extends DataObject{
    static $db = array(
    ...
    'Datum' => 'Date',
    ...
    );

    static $has_one = array(
    'Agenda'=>'Agenda'
    );

    public static $default_sort='Datum';

    function getCMSFields() {
    $fields = new FieldList(
    ...
    $dateField = new DateField('Datum', 'Datum'),
    ...
    );
    $dateField->setConfig('showcalendar', true);
    $dateField->setConfig('dateformat','dd-MM-yyyy');
    return $fields;
    }

    }
    ?>

    Agenda.php

    <?php
    class Agenda extends Page {
    public static $has_many = array(
    'AgendaItems' => 'AgendaItem'
    );

    ...

    }
    class Agenda_Controller extends Page_Controller {
       ...
    public function getAgendaView(){
    $datums = GroupedList::create(AgendaItem::get()->sort('Datum', 'Asc'));
    return $datums;
    }
    }

    Agenda.ss

    ...
    <% if getAgendaView %>
    <% loop AgendaView.GroupedBy(Datum) %>
    <h2>
    $Datum.Nice <== not working
    $Datum.DayOfMonth <== not working
    $Datum.FormatI18N('%B') <== not working
    $Datum.Year <== not working
    $Datum <== works!
    </h2>
    <% loop Children %>
    <div id="agen$ID">
    <div class="tijd">$Tijd</div>
    <div class="titel"><a href="javascript:void(0);" onclick="showhide($ID);">$Titel</a></div>
    </div>
    <% end_loop %>
    <% end_loop %>
    <% end_if %>
    ...

    anyone?

  • quanto
    Avatar
    Community Member
    81 Posts

    Re: DayOfMonth not working in GroupedList Link to this post

    I fixed it by editing Agenda.ss:

    ...
    <% if getAgendaView %>
    <% loop AgendaView.GroupedBy(Datum) %>

    <% loop Children %>
    <% if First %>
    <h2> $Datum.Nice</h2>
    <% end_if %>
    ...
    <% end_loop %>
    <% end_loop %>
    <% end_if %>

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