TableServer Editor fields make them data driven/dynamic?

TableServer Editor fields make them data driven/dynamic?

YoDavishYoDavish Posts: 123Questions: 46Answers: 3

I have editor v 1.9.6. I've been tasked with trying to use create the tableServer.php where the fields are data driven from a database. Is this even possible?

Currently the hard coded fields look something like this:

Editor::inst( $db, 'table1', 'id')
->fields(
Field::inst('table1.col1'),
Field::inst('table1.col2'),
Field::inst('table1.col3'),
Field::inst('table1.col4'),
Field::inst('table1.col5')
)
->leftJoin( 'table2', 'table2.id', '=', 'table1.col2' )
->leftJoin( 'table3', 'table3.id', '=', 'table1.col3' )
->where( function ($q) {
$q->where('table1.col2', NULL, '!=');
$q->where('col2', '2', '!=');
})

Rather than having to hardcode "Field::inst('table1.col1'), etc..." I have it in a table and that data is converted into an array that matches exactly as the hard coded one. I don't think replacing the hard coded fields with the array variable or echo the array variable will work. Is this even possible?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin
    Answer ✓

    Is this even possible?

    Sure. The key thing to remember with the chained API is that the code you have above is functionally the same as:

    $editor = Editor::inst( $db, 'table1', 'id');
    
    $editor->fields(Field::inst('table1.col1'));
    $editor->fields(Field::inst('table1.col2'));
    $editor->fields(Field::inst('table1.col3'));
    $editor->fields(Field::inst('table1.col4'));
    $editor->fields(Field::inst('table1.col5'));
    
    $editor->leftJoin( 'table2', 'table2.id', '=', 'table1.col2' );
    $editor->leftJoin( 'table3', 'table3.id', '=', 'table1.col3' );
    $editor->where( function ($q) {
      $q->where('table1.col2', NULL, '!=');
      $q->where('col2', '2', '!=');
    });
    

    From there you will be able to see how you can build up an Editor instance based on an array of data - or whatever your configuration for the dynamic table is.

    Allan

Sign In or Register to comment.