Parent-Child Tables

Parent-Child Tables

GMGrayingGMGraying Posts: 12Questions: 6Answers: 1

I want to do the same thing as shown on the blog 2016-03-25 Parent/Child editing. Is there any place where I can see the complete code for the users.php file for this example?

Answers

  • allanallan Posts: 63,089Questions: 1Answers: 10,388 Site admin

    Hi,

    Its basically that which is shown in the Server-side (PHP) section - I just removed the include and use statements for brevity:

    <?php
    
    // DataTables PHP library
    include( 'DataTables.php" );
    
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;
    
    if ( ! isset($_POST['site']) || ! is_numeric($_POST['site']) ) {
        echo json_encode( [ "data" => [] ] );
    }
    else {
        Editor::inst( $db, 'users' )
            ->field( 
                Field::inst( 'users.first_name' ),
                Field::inst( 'users.last_name' ),
                Field::inst( 'users.phone' ),
                Field::inst( 'users.site' )
                    ->options( 'sites', 'id', 'name' )
                    ->validator( 'Validate::dbValues' ),
                Field::inst( 'sites.name' )
            )
            ->leftJoin( 'sites', 'sites.id', '=', 'users.site' )
            ->where( 'site', $_POST['site'] )
            ->process($_POST)
            ->json();
    }
    

    Regards,
    Allan

This discussion has been closed.