Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Control children by condition

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: 1135 Views
  • Roelfsche
    Avatar
    25 Posts

    Control children by condition Link to this post

    hallo,

    after reading a while, i was trying to access children of an EventHolderPage from within that page. but my function seem's not to work. thus i think this is basic functionality. what do i make wrong?
    here is the code:
    EventHolder.php:
    <?php

    class EventHolder extends SiteTree {
    static $db = array(
    );
    static $has_one = array(
    );

    static $allowed_children = array('EventPage');
    }

    class EventHolder_Controller extends ContentController {
    function init() {
    parent::init();
    }

       function validEvents()
       {
    return DataObject::get('EventPage', "Verfallsdatum > " . date('Y-m-d'));
    }
    }
       
    in EventHolder.ss i try the following:

    <% control validEvents %>
    <div><h2 style="margin-bottom: 0px; text-align: left; font-family: Arial;">$Ueberschrift</h2></div>
    <div style="width: 530px;">$Bild.SetWidth(100) $Content</div>
    <div style="clear: both">&nbsp;</div>
    <% end_control %>

    the result is every event-page is shown no matter which value i use as condition.
    i think there is no mistake inside the code, may be the system clock of my provider goes wrong?
    Thank you,
    roelfsche

  • Willr
    Avatar
    Forum Moderator
    5503 Posts

    Re: Control children by condition Link to this post

    rather then usingn date() you best bet is to use MySQL Friendly NOW() so you would rewrite that as

    function validEvents() {
    return DataObject::get('EventPage', "Verfallsdatum > NOW()");
    }

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