Custom PHP function Problem

Custom PHP function Problem

alf007alf007 Posts: 37Questions: 15Answers: 0

Hi!

I'm having a problem inside the postCreate server side function. Inside this function I call another one that I have in another php file. But when it calls it, it send the following message.

invalid data source name

Here is my code:

Field

Field::inst( 'colonos.correo' )->set( Field::SET_CREATE )

postCreate

->on( 'postCreate', function ( $editor, $values ) {
        
        $correo = $values['colonos']['correo'];
        Crea_Directorio($correo);
        
        $editor
        ->field( 'colonos.correo' )
        ->setValue( $correo );
    } )

I hope you can help me with this.

Thanks

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    It's a PDO error. Presumably your "other" PHP file cannot see your db connection details. Google your error message for solution.

  • alf007alf007 Posts: 37Questions: 15Answers: 0
    edited May 2017
    // DataTables PHP library and database connection
        include( "DataTables.php" );
        include("../../my_functions.php");
    

    Thanks @tangerine, I include another php file that makes another conection to the database. This could probably make a conflict between the conection that the DataTables has and the new one that I need for my function right?

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    Its possible, but it should be that you can have multiple connections to the database running together.

    What is the full backtrace for the error message?

    Allan

  • alf007alf007 Posts: 37Questions: 15Answers: 0
    edited May 2017

    Hi, the problem was that I defined the PDO conection with constants in the another file so it didn't had the parameters to connect. I solved this but I noticed that the function postCreate doesn't have the value of the variable $correo it has a number (1). But if I use the preCreate it has the original value.

    How can I get the original value of the variable $correo in the postCreate?

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin
    Answer ✓

    How can I get the original value of the variable $correo in the postCreate?

    You can't unless you have stored it somewhere else. By the time the postCreate method is called, it has already been overwritten. If you need it from before the update, use preCreate and query the database to get the current value.

    Allan

  • alf007alf007 Posts: 37Questions: 15Answers: 0

    Thanks @allan

This discussion has been closed.