Data from outside SQL sent to client

Data from outside SQL sent to client

mdesignmdesign Posts: 72Questions: 17Answers: 0

Hi,

is there a way to add data to the SSP file that does not come from the SQL tables but is created by PHP?

In my example, I'm displaying news items in the Editor table. In the SSP I'd like to add the amount of files in a certain folder (its name contains the SQL id) and show this number in the DataTable as additional column. This column, of course, can not be edited by the client.

My SSP at the moment looks like this:

$editor = Editor::inst(
  $db, 'tablename', 
       'tablename.id' /* Primary Key */
)
->fields(
  Field::inst('...all columns...'),
);

I have no clue how to 'sideload' additional PHP-generated data. Can you help me out? Thx

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    Answer ✓

    Hi,

    Yes indeed - you want to use the Editor->data() method rather than Editor->json().

    Basically all Editor->json() does is:

    $json = $editor->data();
    echo json_encode($json);
    

    So to modify the data Editor returns to the client-side you would do something like:

    $editor = Editor::inst( ... )
      ->fields(....);
    
    $editor->prcoess($_POST);
    $data = $editor->data();
    
    $data['myExtraInfo'] = ['Hello', 'world'];
    
    echo json_encode($data);
    

    Allan

  • mdesignmdesign Posts: 72Questions: 17Answers: 0

    Dear Allan,
    thanks a lot for this answer, that solved the problem.

This discussion has been closed.