Help with Datatables Editor in CiviCRM Extension (POST ERROR)
Help with Datatables Editor in CiviCRM Extension (POST ERROR)
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
It sounds like the
$db
variable that is being passed in isnull
. If you addvar_dump( $db );
immediately before that line, what does it show? How are you initialising that variable?Allan
Yep, that is the issue. I was under the impression that the variable was automatically defined as stated in the documentation:
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?
Its defined in the Bootstrap.php file of the Editor libraries. Its possible you haven't included that perhaps?
Allan
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!