I'm attempting to recreate the following in PHP dynamically:
Editor::inst( $db, 'user_to_groups')
->field(
Field::inst( 'user_to_groups.user' ),
Field::inst( 'user_to_groups.group' )
->options( Options::inst()
->table('groups')
->value('ID')
->label('groupname')
)
->validator( 'Validate::dbValues' ),
Field::inst( 'groups.groupname' )
)
->where('user',25)
->leftJoin( 'groups', 'groups.id', '=', 'user_to_groups.group' )
->process($_POST)
->json();
So far, my attempt has yielded:
$editor = new Editor( $db, $tablename, $tablekey );
$editor->fields(new Field("user_to_groups.user"));
$editor->fields(new Field("user_to_groups.group"));
$editor->fields(Field("user_to_groups.group"))->options( 'groups','ID','groupname' );
$editor->fields(Field("user_to_groups.group"))->validator( 'Validate::dbValues' );
$editor->fields(new Field("groups.groupname"));
$editor->where('user','25');
$editor->leftJoin( 'groups', 'groups.id', '=', 'user_to_groups.group' );
$editor->process( $_POST ) ->json();
I think the first 3 lines are correct. Can you please provide guidance on correct syntax for setting options, validator, and joins?