When you add a new entry and press save, the success message includes a link to modify the inserted entry or go back to list. However, if I use callback_insert, the link will always point to /edit/1. This is because of the following code in libraries/grocery_crud.php:
protected function db_insert($state_info)
.........
$callback_return = call_user_func($this->callback_insert, $post_data);
if($callback_return === false)
return false;
}
}
if(isset($insert_primary_key))
return $insert_primary_key;
else
return true;
Because primary key is not set, it simply returns true, which is equal to 1.
In order to fix this, I simply modified the code above like this:
if($callback_return === false)
return false;
/* Added this line: */
else $insert_primary_key = $callback_return;
So now I can return the inserted primary key in the callback and the link is correct.