Errors on updating and creating

Errors on updating and creating

rwgreenwoodrwgreenwood Posts: 43Questions: 13Answers: 0

I am unable to update or create from editor. I am using a postgres database.
For updating, the error returned is :
<b>Notice</b>: Undefined index: id in <b>/php/lib/Editor/Editor.php on line 501
My id field is not "id", but I have set the correct name in the idSrc, as well as in the Editor::inst parameter.

The create error is the following:
Call to a member function insertId() on a non-object in /php/lib/Editor/Editor.php</b> on line <b>1109
The post parameters look correct.

If it is significant, I have a join in my server-side php to get a related table for a select field options. I also have a where so that the datatable is filtered.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin

    Hi,

    Have you configured the PHP Editor instance to tell it what the primary key column name is? You can do so by passing a string (the column name) as the third parameter to the Editor constructor.

    Allan

  • rwgreenwoodrwgreenwood Posts: 43Questions: 13Answers: 0

    Allan,
    Yes, I have done that. I have a join table, so I have tried with the tablename.columnname and just columnname in the third parameter. Same result on both errors. On the edit, it pulls up the record correctly, but I assume that is just grabbing it from the datatable.

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin

    If you use the third parameter in the Editor constructor you should need to set idSrc - Editor will see it automatically.

    Can you show me your full PHP please.

    Allan

  • rwgreenwoodrwgreenwood Posts: 43Questions: 13Answers: 0
    edited February 2016

    Here you go.
    As I mentioned, I've tried with both just history_id as well as case_history.history_id. I've included it as a field as well as left it out.

    Thanks so much

    <?php
    
    /*
     * Editor server script for DB table case_history
     * Created by http://editor.datatables.net/generator
     */
    
    // DataTables PHP library and database connection
    include( "lib/DataTables.php" );
    $case_id = '';
    if (isset($_REQUEST['case']) && $_REQUEST['case'] ) {
      $case_id = $_REQUEST['case'];
    
    }
    
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;
    
    
    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'case_history', 'history_id' )
        ->fields(
            Field::inst( 'case_history.case_id' ),
            Field::inst( 'case_history.history_date' )
        ->validator( 'Validate::dateFormat', 'm/d/Y' )
        ->getFormatter( 'Format::date_sql_to_format', 'm/d/Y' ),
            Field::inst( 'case_history.staff_id' )
          ->options( 'staff', 'staff_id', 'staff.first_name || \' \' || staff.last_name' ), 
        Field::inst('staff.last_name'),
        Field::inst('staff.first_name'),
            Field::inst( 'case_history.history_action' ),
            Field::inst( 'case_history.contact_type' ),
            Field::inst( 'case_history.contact_name' ),
            Field::inst( 'case_history.notes' ),
        Field::inst('case_history.history_id')
        )
      ->leftJoin('staff','staff.staff_id', '=', 'case_history.staff_id')
      ->where('case_history.case_id', $case_id, '=')
        ->process( $_POST )
        ->json();
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin

    Hi,

    Thanks for the code!

    Try removing:

    Field::inst('case_history.history_id')
    

    and also remove the idSrc option in your Javascript. As I say, since you have used the third parameter in the Editor PHP constructor, it isn't needed.

    Allan

  • rwgreenwoodrwgreenwood Posts: 43Questions: 13Answers: 0
    edited February 2016

    Allan,
    I have removed the field inst for the id field as you suggested, as well as the idSrc. Same error. The line causing the error (at least on the editing piece) in Editor.php is:

    $this->_update( $data['id'] );

    Here is a var_dump of the data array right before the error:

    array(3) {
      ["action"]=>
      string(4) "edit"
      ["data"]=>
      array(1) {
        ["row_3532"]=>
        array(1) {
          ["case_history"]=>
          array(5) {
            ["history_date"]=>
            string(10) "10/08/2015"
            ["case_id"]=>
            string(4) "2595"
            ["history_action"]=>
            string(21) "Reimbursement Request"
            ["staff_id"]=>
            string(1) "8"
            ["notes"]=>
            string(16) "Request received"
          }
        }
      }
      ["case"]=>
      string(4) "2595"
    }
    
    
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Are you using the same version of the PHP libraries as the Javascript (ideally both 1.5.4 - the current release)? And have you not got the legacyAjax option set in your Editor configuration?

    Allan

This discussion has been closed.