Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Using SSDatetime functions inside the controller


Go to End


4 Posts   1917 Views

Avatar
ddshore

Community Member, 12 Posts

13 February 2010 at 5:30am

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?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

13 February 2010 at 6:19am

You need to get the fields as an object.

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

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

Avatar
ddshore

Community Member, 12 Posts

13 February 2010 at 6:35am

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!

Avatar
UncleCheese

Forum Moderator, 4102 Posts

13 February 2010 at 6:52am

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.