Jump to content

Method TableRow::getUnformatted does not exist or is not callable in this context


Tyssen
 Share

Recommended Posts

I'm trying to compare a date output by a ProFields table field to the current date and have read in the forums that I need to use getUnformatted, but when I do, I get the error in the thread title.

Does comparing dates within tables require special consideration?

Link to comment
Share on other sites

foreach($page->draw as $draw) :
  echo $draw->getUnformatted("date");
endforeach;

With this I get:

Error: Exception: Method TableRow::getUnformatted does not exist or is not callable in this context (in /wire/core/Wire.php line 349)

Link to comment
Share on other sites

You can't do that (getUnformatted is method of Page object, tableRow doesn't have that), but you can do:

$raw = $page->getUnformatted("draw");

var_dump($raw);

But in your case it might be easier just to convert your field into timestamp:

$timestamp = strtotime("pretty much any date format");

  • Like 3
Link to comment
Share on other sites

  • 3 months later...

For anyone wanting to getUnformatted regardless, you can do this:

$page->getUnformatted('dates_table.begin_date');
/* Returns:
 * array(8) {
 * 	[0]=> int(1430863200)
 * 	[1]=> int(1433282400)
 * 	[2]=> int(1434837600)
 * }
 */

Also:

$page->getUnformatted('dates_table.first.begin_date');
// Returns int(1430863200)

$page->getUnformatted('dates_table.last.begin_date');
// Returns int(1434837600)

So you can have your cake and eat it too without having to parse date strings. E. g. you can directly use the inbuilt templating syntax with formatted values, but if, say, you also need a locale aware day name, you can feed the timestamp to strfrtime().

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...