Sorry if asked before. Is it possible to set the Field definitions dynamically from an array?

Sorry if asked before. Is it possible to set the Field definitions dynamically from an array?

cemlimitedcemlimited Posts: 36Questions: 9Answers: 0

$fields = array("test2","test2");

Editor::inst( $db, 'register' )

foreach($fields as $field){
->field(Field::inst( $field ))
}

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,226Questions: 1Answers: 10,416 Site admin
    Answer ✓

    Sure:

    $fields = array("test2","test2");
    
    $editor = Editor::inst( $db, 'register' );
    
    foreach($fields as $field){
      $editor->field(Field::inst( $field ));
    }
    

    See our little bit of documentation on chaining here if you aren't familiar with using that technique.

    Allan

  • cemlimitedcemlimited Posts: 36Questions: 9Answers: 0

    Thanks Allan.
    Instantiation not that easy....but figured the syntax out now...Thanks for the help

This discussion has been closed.