Error when trying to use $this-> inside of callbacks
When i try to use any of callbacks that require use of this-> inside of it o get this error:
Uncaught Error: Using $this when not in object context in
$crud->callbackAfterInsert(function ($stateParameters) { $this->db->where('id', $stateParameters->insertId);
Throws error at 2nd line of code. (just snip of callback)
Here is full:
<?php include("libraries/autoload.php"); use GroceryCrud\Core\GroceryCrud; $database = include('database.php'); $config = include('config.php'); $crud = new GroceryCrud($config, $database); $crud->setTable('list'); $crud->setSubject('Contract', 'Contracts'); $crud->setRead(); $crud->readOnlyFields(['CONTRACT_TYPE','DAY']); $crud->callbackAfterInsert(function ($stateParameters) { $this->db->where('id', $stateParameters->insertId); $record = $this->db->get('list')->row(); if (!empty($record)) { $this->db->update('list', ['LF_TOCID' => 11], ['id' => $stateParameters->insertId]); } return $stateParameters; }); $output = $crud->render(); if ($output->isJSONResponse) { header('Content-Type: application/json; charset=utf-8'); echo $output->output; exit; } $css_files = $output->css_files; $js_files = $output->js_files; $output = $output->output; include('view.php');
Spend whole day trying to fix it.
Can someone help?
Thanks.