cascading lists example

cascading lists example

gixxy22gixxy22 Posts: 13Questions: 6Answers: 1

Im a little confused with the cascading lists, in the editor setup it shows:

 ajax: "../php/cascadingLists.php"

and in the dependent it shows

  editor.dependent( 'team.continent', '../php/countries.php' );

however there is only 1 example php file given, is there another PHP example file to go with this?

Answers

  • allanallan Posts: 56,888Questions: 1Answers: 9,042 Site admin

    This is what countries.php looks like:

    <?php
    
    // DataTables PHP library
    include( "../lib/DataTables.php" );
    
    $values = $_REQUEST['values']['team.continent'];
    if (! $values) {
        echo json_encode( [] );
        return;
    }
    
    $countries = $db
        ->select( 'country', ['id as value', 'name as label'], ['continent' => $_REQUEST['values']['team.continent']] )
        ->fetchAll();
    
    echo json_encode( [
        'options' => [
            'team.country' => $countries
        ]
    ] );
    

    Fairly basic - it queries the database for the options basic on the condition submitted. The full API for our Database class is documented here if you want to use it.

    Apologies for the confusion with that extra file. It is included in the PHP download package if you want to grab it from there.

    Regards,
    Allan

Sign In or Register to comment.