Jump to:

3429 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Expires.InPast not working right

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

Page: 1
Go to End
Author Topic: 1487 Views
  • frabraha
    Avatar
    Community Member
    49 Posts

    Expires.InPast not working right Link to this post

    I've been trying to make the InPast function to work.

    $Expires.InPast outputs 1 when its out of date, but when I run a <% if Expires.InPast %>..<% end_if %> it doesn't to anything with it and shows every article..

    Any idea why or what I'm doing wrong?

  • dynamite
    Avatar
    Community Member
    66 Posts

    Re: Expires.InPast not working right Link to this post

    I am banging my head against the wall on this problem, too!

    Did you find a solution? If so, I would be very interested in what you came up with! Thanks in advance.

  • spierala
    Avatar
    Community Member
    80 Posts

    Re: Expires.InPast not working right Link to this post

    I have this problem too!
    florian

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Expires.InPast not working right Link to this post

    Hmmm... Lots of people seem to be having trouble getting this to work. I never have needed to use it, so I can't say from experience where the issue lies. However, i do have a solution.

    Simply, when you do this on an item, it will be a property of a DataObject, so we can simply build a method into the model called 'hasExpired'.

    Simply in the model we need to create a method:

    class Page extends SiteTree {
    ...
    public function hasExpired() {
    return (strtotime($this->Date) < time());
    }
    }

    Now, in your template you can do:

    <% if hasExpired %>
    ...
    <% end_if %>

    Obviously 'Date' will have to be declared in the $db array with date type

    I hope that helps

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