Help with Datatables Editor in CiviCRM Extension (POST ERROR)

Help with Datatables Editor in CiviCRM Extension (POST ERROR)

clearriverchurchclearriverchurch Posts: 3Questions: 1Answers: 1

Has anyone successfully gotten Editor to load data on CiviCRM? I have tried this as an API call and as a Civi PHP Extension Page. Both give me the same error.

I am able to successfully connect to the DB.

Here is the code:

$editor = Editor::inst( $db, 'civicrm_contact' ) ->fields( Field::inst( 'sort_name' ), Field::inst(' id' ) ->post( $_POST ) ->json();

The error I get is "Call to member function transaction() on null" - line 884 of Editor.php. I also get POST 500 error.

Any help would be greatly appreciated.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,714Questions: 1Answers: 10,103 Site admin

    It sounds like the $db variable that is being passed in is null. If you add var_dump( $db ); immediately before that line, what does it show? How are you initialising that variable?

    Allan

  • clearriverchurchclearriverchurch Posts: 3Questions: 1Answers: 1

    Yep, that is the issue. I was under the impression that the variable was automatically defined as stated in the documentation:

    The $db variable was automatically defined as an instance of the Database() class which was used along with the $sql_details variable to establish a connection with the database automatically. The $db variable is defined in the Bootstrap.php library file and the variable name can be changed there if you require.

    I'm not sure why the $db variable is not globally accessible. I have it initialized by global $db; however it is still null.

    Any suggestions?

  • allanallan Posts: 61,714Questions: 1Answers: 10,103 Site admin

    Its defined in the Bootstrap.php file of the Editor libraries. Its possible you haven't included that perhaps?

    Allan

  • clearriverchurchclearriverchurch Posts: 3Questions: 1Answers: 1
    Answer ✓

    Unfortunately that is not it. Datatables.php is including Bootstrap.php. I can do the dump from bootstrap.php and it is not null. I ended up just putting the config.php code directly in my PHP API file for the CiviCRM extension. When I do this it works. Thanks for helping me at least figure out how to move forward!

This discussion has been closed.