cascading lists example

cascading lists example

gixxy22gixxy22 Posts: 15Questions: 7Answers: 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: 61,669Questions: 1Answers: 10,096 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.