setValue from SESSION variable
setValue from SESSION variable
KeepMoving
Posts: 28Questions: 7Answers: 0
Hi Im trying to set the value of a session variable and use it in a "where condition",
I've read this https://editor.datatables.net/manual/php/conditions#Setting-field-values
but I just cant get what I want
Im doing this
include( "../../php/DataTables.php" );
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate;
$editor->field(
new Field( 'userid' )
->setValue($_SESSION['IdUsuario'])
);
$db->sql( "SET NAMES 'utf8'" );
Editor::inst( $db, 'altaestudios', 'IdAltaEstudios')
->fields(
Field::inst('altaestudios.FechaEstudio')
->validator( 'Validate::dateFormat', array(
"format" => Format::DATE_ISO_8601,
"message" => "Ingrese un formato válido de fecha yyyy-mm-dd"
) )
->getFormatter( 'Format::date_sql_to_format', Format::DATE_ISO_8601 )
->setFormatter( 'Format::date_format_to_sql', Format::DATE_ISO_8601 ),
Field::inst('altaestudios.activo'),
Field::inst('altaestudios.archivo'),
Field::inst('archivo.web_path'),
Field::inst('altaestudios.IdTipoEstudio'),
Field::inst('tipoestudio.NombreEstudio')
)
->leftJoin('tipoestudio', 'altaestudios.IdTipoEstudio', '=', 'tipoestudio.IdTipoEstudio')
->leftJoin('archivo', 'altaestudios.archivo', '=', 'archivo.IdArchivo')
->where('altaestudios.IdUsuario','userid') // my new variable if I set a number like 63 I get results.
->process( $_POST )
->json();
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You are using
->setValue($_SESSION['IdUsuario'])
which is fine, but you need to include it in the Editor instance that is being used to process the inbound data:In fact, are you not getting an error in PHP stating that
$editor
doesn't exist? It isn't defined anywhere.Move that field definition into the
fields()
call at line 21.Allan
Actually yes im getting an error
So I have to do this?
Probably need to include the
altaestudios.
table name as well (assuming that is the correct name), like you have with the other fields, since you are using a join.Thanks,
Allan
Thanks for your time Allan, I really apreciate your help
but now Im getting this error
DataTables warning: table id=paciente - Ajax error. For more information about this error, please see http://datatables.net/tn/7
Have you followed the diagnostic instructions provided at that link?
I think i did.. but not sure
What does the network tab in your browser's inspector tools show? The information in the tech note show how to do that if you aren't sure.
Allan
Hi allan I had an extra comma and after I removed I got this in network > xhr
Notice: Undefined variable: _SESSION in /home/unidadgenetica/public_html/SistemaUG/genetica/scripts/r_Paciente.php on line 42
Fatal error: Uncaught Error: Call to a member function dbField() on null in /home/unidadgenetica/public_html/SistemaUG/php/Editor/Editor.php:1827 Stack trace: #0 /home/unidadgenetica/public_html/SistemaUG/php/Editor/Editor.php(846): DataTables\Editor->_prepJoin() #1 /home/unidadgenetica/public_html/SistemaUG/php/Editor/Editor.php(661): DataTables\Editor->_process(Array) #2 /home/unidadgenetica/public_html/SistemaUG/genetica/scripts/r_Paciente.php(51): DataTables\Editor->process(Array) #3 {main} thrown in /home/unidadgenetica/public_html/SistemaUG/php/Editor/Editor.php on line 1827
Looks like you need to call
session_start()
.Was that the extra comma you removed?
Allan
this one
When I set the comma I get an error
And even without comma I dont get results
So are you calling session_start() anywhere?
Hi tangerine, yes at the top
Yes you would there, as that is a PHP syntax error. Remove that comma for it to be valid PHP.
Do you get any errors, or is it just that the data is an empty array?
Allan
This is what i get
thanks
That's what the server is returning? That doesn't look like valid JSON. DataTables should be showing an
alert
for such cases.Could you give me a link to the page so I can check it out?
Allan
I'll pm you page and access to the test
Its working, thanks for your time
Hi all, same problem here: solutions?
thanks
Same question as above, what is the server returning?
Also again, if you give me a link to the page I can check it out.
Allan