1

I'm trying to use http://devot-ee.com/add-ons/rest. In a few of my pages, I am getting this error when I enable debug mode:

A PHP Error was encountered

Severity: Warning
Message: strtotime() expects parameter 1 to be string, array given
Filename: rest/pi.rest.php
Line Number: 351

The relevant part of the code in pi.rest.php is this:

// Format dates to unix timestamps
elseif (isset($this->EE->TMPL->date_vars[$index]) and ! is_numeric($child))
{
    $child = strtotime($child);
}

I've tried outputting the value of $child before the strtotime call, and I see:

array(1) { ["profile_name"]=> string(18) "John Doe" }

The output is the array representation of the JSON string I expect to be returned to me.

Any ideas what be causing my issues?

UPDATE 1:

One of the problems exist when the REST tags are called from inside:

{exp:low_search:results
   {if embed:query}query="{embed:query}"{/if}
   collection="forum_topics"
   disable="categories|category_fields"
   limit="25"
   paginate="bottom"
   orderby="date"
   sort="desc"
}

When I replace that with just {exp:channel:entries} (and remove the query param, and replace collection with channel), the problem is gone. So, it has something to do with Low Search???

Update 2:

The other place where this add-on is having issues is when it is inside of:

{exp:friends:mine
    member_id="CURRENT_USER"
    reciprocal="y"
}

Update 3:

I did a var_dump in the part of the code that encounters the error. $this->EE->TMPL->date_vars has the value array(1) { [0]=> string(10) "entry_date"}. $index is int(0). And $child has the array that I need.

  • Which version of EECMS are you using, please? – Robson Sobral Jun 24 '14 at 17:56
  • 2.8.1 - hope this helps! – ExpressionEngineNewbie Jun 24 '14 at 21:54
  • Yeap, it helps. Please, show us the part of the template where the value of profile_name should appears. – Robson Sobral Jun 24 '14 at 22:00
  • Did you fix this? What ended up being the solution? I am struggling with the same issues. :-/ – Jacob Graf Sep 29 '14 at 15:24
1

ExpressionEngine has had some updates to do date localization and relative dates. The particular line from the core that is causing your issue is Line 4166 in expressionengine/libraries/Template.php.

There are a number of solutions here for your problem.

Ideally line 349 should check to make sure it is a string as well because strtotime will only work as expected with a format string.

isset($this->EE->TMPL->date_vars[$index]) && is_string($child) && !is_numeric($child))

Additionally it could utilize a different tag parameter as well on line 65.

$format = $this->EE->TMPL->fetch_param('response_format', 'xml');

Either of these changes should do the trick for this scenario, personally I would do both.

If you have a response that comes back as a numeric string it will still try to process it as a date if you don't change the template tag.

I believe the reason you are seeing it only with the low_search tag is because you are triggering date processing with the orderby="date".

| improve this answer | |
1

EE 2.8 will consider any tag variable that contains "format=", "timezone=", or ":relative" a date variable. Do you have any tags within your exp:rest tag pair that contain any of those phrases? For example, these made up variables would be considered date variables: {foo format="%Y"}, {bar timezone="America/Chicago"}, and {oldest:relative}.

| improve this answer | |
  • Yes, {exp:rest url="/api/profile-images/" format="json" param:current_profile_member_id="{author_id}" parse="inward" random verb="get"} -- but it only causes problems in some pages, not all. I'm still not sure how they are different from page to page (I'm pretty much copying/pasting the code). Anyway, so it does contain format -- why it that a problem? – ExpressionEngineNewbie Jun 25 '14 at 22:50
  • I've updated my question. – ExpressionEngineNewbie Jun 26 '14 at 1:47
  • I'd try to var_dump($this->EE->TMPL->date_vars); where that error is occurring in pi.rest and see what the hell is in there. It sounds like for some reason it's grabbing exp:rest as a date var because of the format= parameter. – Rob Sanchez Jun 26 '14 at 2:21
  • May as well var_dump($index) while you're in there. – Rob Sanchez Jun 26 '14 at 2:22
  • Since rest is a plugin and not a module, can you try adding parse="inward" as a parameter to your {exp:rest} tag and see if that works? – Rob Sanchez Jun 26 '14 at 2:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.