Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Using SSDatetime functions inside the controller

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1207 Views
  • ddshore
    Avatar
    Community Member
    12 Posts

    Using SSDatetime functions inside the controller Link to this post

    Hi,
    I'm trying to use SSDatetime funcions inside the controller:
    I've tried several ways, like:
    $thisdatetime = ($previous_vote->datetime);
    if($thisdatetime->IsToday())
    but nothing seems to work.
    Can someone help? What am I doing wrong?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Using SSDatetime functions inside the controller Link to this post

    You need to get the fields as an object.

    $this->obj('MyDateField')->Format('m/d/y');

    $this->obj('MyTextField')->FirstParagraph();

  • ddshore
    Avatar
    Community Member
    12 Posts

    Re: Using SSDatetime functions inside the controller Link to this post

    Wow, thanks a lot.
    A couple of questions, where would the documentation for knowing something like this be?
    Why would this only happen in the controller and not in the view?
    Thanks!

  • UncleCheese
    Avatar
    4085 Posts

    Re: Using SSDatetime functions inside the controller Link to this post

    If you add ?showtemplate=1 to your URL, you'll see how SSViewer parses the template. It always runs ->obj() on those fields before rendering them. Or it runs XML_val(), but I think that's just a wrapper method for obj().

    In a controller or a model, it's rare that you'd want to work with fieldtype objects in your logic, since you don't need to deal with presentation, so the framework has you "opt in" to an object and stores the literal value by default.

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