Warning: date_create_from_format() expects parameter 2 to be string, object given
Warning: date_create_from_format() expects parameter 2 to be string, object given
When I try to Add a new item in Editor and click "Add," I get a "An error has occurred - Please contact the system administrator" message. Firebug returns this response from Post:
Warning: date_create_from_format() expects parameter 2 to be string, object given in "/datatables/php/lib/Editor/Format.php" on line 89
How do I return a string instead of an object? My timezone is correctly set in PHP if that helps. This is my server side script for Editor:
if ( isset($_POST['action']) && $_POST['action'] === 'create' ) {
$_POST['data']['created'] = date_create();
}
Field::inst( 'created' )
->set( isset($_POST['action']) && $_POST['action'] === 'create' ? true : false )
->getFormatter( 'Format::date_sql_to_format', 'm/d/y' )
->setFormatter( 'Format::date_format_to_sql', 'm/d/y' )
This question has an accepted answers - jump to answer
Answers
What version of the PHP libraries for Editor are you using? The current release (1.3.1) doesn't actually have anything on line 89 in
Format.php
.Could you try upgrading and seeing it that helps - I think I remember this issue from before!
Allan
You were right about the PHP libraries being from 1.2.4 (!!!), I forgot to upgrade those when I switched to 1.3.1. Senior moment!
But the error is still occuring. If I remove the following lines, then the error goes away and an entry is added just fine:
Would removing that section cause an issue?
Removing those lines would mean that the
created
field is not set on create - which is possibly not what you want. However, a better solution is probably simply to set the default for that column to benow()
in the SQL table definition rather than having PHP do it.Allan
So I could remove the previously mentioned PHP lines, and replace it with a trigger like this in SQL?