Explanation of ->json( true )

Explanation of ->json( true )

Restful Web ServicesRestful Web Services Posts: 202Questions: 49Answers: 2
edited April 2018 in Editor

Can anyone explain to me how the ->json() function works because I am trying to establish if I can return the JSON data without printing it. According to the documentation json( boolean $print = true ) means "Basically the same as the DataTables\Editor::data() method, but in this case we echo, or return the JSON string of the data."

If I set ->json( false ) I get no output printed which is what I want. However, I still want to be able to return the processed data in this case.

I.e. return $json; but I dont know what if any variable exists which holds the processed data for me to return?

Thanks!

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    edited April 2018 Answer ✓

    Assuming that you are using the Editor, then if you have an Editor instance assigned to $editor then after $editor->process() your data would be in $editor->data().

    The ->json() call is equivalent to "echo json_encode( $editor->data() );"

    edited by allan Mini edit - the echo would be for $editor->data() rather than $this->data().

  • Restful Web ServicesRestful Web Services Posts: 202Questions: 49Answers: 2

    Many thanks for your replies, that really helped. It is working as expected now.

This discussion has been closed.