Call PHP Script in Editor::inst Class

Call PHP Script in Editor::inst Class

pcnwebpcnweb Posts: 4Questions: 1Answers: 0

What's the "Editor" way of calling an external PHP script inside one of the Editor::inst "on" statements?

Ex, "runThis" pseudocode:

->on( 'preCreate', function ( $editor, $values ) {
    // On create update all the other records to make room for our new one
    $editor->db()
        ->query( 'update', 'mobilemenu_fbgt' )
        ->set( 'roworder', 'roworder+1', false )
        ->where( 'roworder', $values['roworder'], '>=' )
        ->exec();
                    ->runThis(file_get_contents('my/file/path.php') )
} )

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    Answer ✓

    There are examples in the documentation:
    https://editor.datatables.net/manual/php/events

  • pcnwebpcnweb Posts: 4Questions: 1Answers: 0
    edited July 2017

    So according to that, I added a simple function above the Editor::inst -

    function updateVOD(){
    $myvar = file_get_contents('http://path/to/my/file.php');
    }

    and appended these to the Editor::inst, after my preCreate and preRemove (which work):

    ->on( 'postCreate', function ( $editor, $values ) {
        updateVOD();
    } )
    ->on( 'postRemove', function ( $editor, $values ) {
        updateVOD();
    } )
    

    No dice, postCreate and postRemove don't fire.

    Where is a working example?

  • pcnwebpcnweb Posts: 4Questions: 1Answers: 0
    edited July 2017

    Should I just call my custom function in the end of the preCreate and preRemove blocks?

  • pcnwebpcnweb Posts: 4Questions: 1Answers: 0
    edited July 2017

    Ok, totally wrong - moving the function call does nothing. Out of ideas for now.

  • allanallan Posts: 63,481Questions: 1Answers: 10,467 Site admin

    Hi,

    What do you want to do with the contents of the PHP file?

    This code:

    function updateVOD(){
    $myvar = file_get_contents('http://path/to/my/file.php');
    }
    

    would simply get the contents of the response (possibly a failure in this case since you are using http:// rather than a local file), and assign it to $myvar, which isn't then used.

    If you want to execute the PHP code in your file you would use include - e.g.:

    function updateVOD () {
      include '/my/path/to/file.php';
    }
    

    I would suggest that a better pattern would be to define the updateVOD() function in your external file and then always include it at the top of the main PHP file.

    Allan

This discussion has been closed.