Custom PHP function Problem
Custom PHP function Problem
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
This discussion has been closed.
Answers
It's a PDO error. Presumably your "other" PHP file cannot see your db connection details. Google your error message for solution.
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?
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
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?
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, usepreCreate
and query the database to get the current value.Allan
Thanks @allan