Newbie question

Newbie question

panzrampanzram Posts: 29Questions: 11Answers: 0

Hi, sorry for a bit of a simple question, but I cannot find the answer in the forum or documentation.

If I have the following table;

staff
id, name

...and I have where clause:

->where( 'staff.id', $_SESSION["staffId"], '=' )

...how can add a new staff and set the staffId to the session staffId?

Txh
Josef

This question has an accepted answers - jump to answer

Answers

  • rpmccormickrpmccormick Posts: 136Questions: 18Answers: 0

    I hope this helps:

       yourJSvar = <?php echo $_SESSION["staffId"]; ?>;
    
       yourEditorVar= new $.fn.dataTable.Editor(...);
    
        // When New button is pressed
        yourEditorVar.on('initCreate', function (e, json, data)
         {yourEditorVar.field('ID').set(yourJSvar);
         }         );
    
  • fabioberettafabioberetta Posts: 74Questions: 23Answers: 4
    edited August 2015 Answer ✓

    you can also do it directly in the PHP file so you do not have to worry in the client.

    an example that I am using.

    Field::inst( 'child.account_id' )
                ->set( Field::SET_CREATE )
                ->setValue( $_SESSION['account_id'] ))
    

    remeber to start the session in the php file.

    // DataTables PHP library
    include( "../Editor-1.5.0/php/DataTables.php" );
    
    // start session to get session user data
    session_start();
    
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Join,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;
    
    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'child' )
        ->fields(
            Field::inst( 'child.id' ),
            Field::inst( 'child.first_name' ),
            Field::inst( 'child.last_name' ),
            Field::inst( 'child.birth_date' ),
            Field::inst( 'child.sex' ),
            Field::inst( 'child.photo' )
                    ->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/_school_files/__ID__.__EXTN__' ) 
                        ->db( 'file', 'id', array(
                                            'fileName'    => Upload::DB_FILE_NAME,
                                            'fileSize'    => Upload::DB_FILE_SIZE,
                                            'fullPath'    => Upload::DB_WEB_PATH
                        ) )
                    ),
            Field::inst( 'child.section_id' )
                    ->options( 'section', 'id', 'name' ),
            Field::inst( 'section.name' ),
            Field::inst( 'section.color' ),
            Field::inst( 'child.account_id' )
                ->set( Field::SET_CREATE )
                ->setValue( $_SESSION['account_id'] ))
        ->where( 'child.account_id', $_SESSION['account_id'] )
        ->leftJoin( 'section', 'section.id', '=', 'child.section_id' )
        ->process( $_POST )
        ->json();
    
  • panzrampanzram Posts: 29Questions: 11Answers: 0

    Thank you both for your solutions...fabioberetta's way seems more logical to me. I'll try that.

  • panzrampanzram Posts: 29Questions: 11Answers: 0

    ...it worked like a charm. Thanks again!

This discussion has been closed.