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

emtemt Posts: 46Questions: 10Answers: 0
edited June 2014 in Editor

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

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    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

  • emtemt Posts: 46Questions: 10Answers: 0

    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:

    if ( isset($_POST['action']) && $_POST['action'] === 'create' ) {
        $_POST['data']['created'] = date_create();
    }
    

    Would removing that section cause an issue?

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Answer ✓

    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 be now() in the SQL table definition rather than having PHP do it.

    Allan

  • emtemt Posts: 46Questions: 10Answers: 0
    edited June 2014

    So I could remove the previously mentioned PHP lines, and replace it with a trigger like this in SQL?

    BEGIN
    IF NEW.created = '0000-00-00 00:00:00' THEN
    SET NEW.created = NOW();
    END IF;
    END
    
This discussion has been closed.