where function does not work

where function does not work

MadMax76MadMax76 Posts: 149Questions: 33Answers: 1

Hi,

using this controller:

<?php
include( "../lib/DataTables.php" );
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate,
    DataTables\Editor\ValidateOptions;

session_start();

$freig_person = $_SESSION["PID"];

// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'freigabe', 'ID_freigabe')
    ->readTable('V_Rechnungern_mit_freig')
    ->fields(
        Field::inst( 'V_Rechnungern_mit_freig.ID_freigabe' )->set(false),
        Field::inst( 'V_Rechnungern_mit_freig.Re_Empfaenger' ),
        Field::inst( 'V_Rechnungern_mit_freig.KUN_KundeBez' ),
        Field::inst( 'V_Rechnungern_mit_freig.INP_ID' ),
        Field::inst( 'V_Rechnungern_mit_freig.Stapelname' ),
        Field::inst( 'V_Rechnungern_mit_freig.freig_erledigt' )
            ->setFormatter( function ( $val, $data, $opts ) {
                return ! $val ? 0 : 1;
            } ),
        Field::inst( 'V_Rechnungern_mit_freig.Lieferant' ),
        Field::inst( 'V_Rechnungern_mit_freig.LiefenantenNo' ),
        Field::inst( 'V_Rechnungern_mit_freig.Rechnungsdatum' ),
        Field::inst( 'V_Rechnungern_mit_freig.Rechnungsnummer' ),
        Field::inst( 'V_Rechnungern_mit_freig.fehlersuche' ),
        Field::inst( 'V_Rechnungern_mit_freig.Netto' ),
        Field::inst( 'V_Rechnungern_mit_freig.Brutto' ),
        Field::inst( 'V_Rechnungern_mit_freig.freig_angefordert_wann' )
            ->getFormatter( Format::dateSqlToFormat( 'Y-m-d' ))
            ->setFormatter( Format::dateFormatToSql('Y-m-d' )),
        Field::inst( 'V_Rechnungern_mit_freig.freig_angefordert_wie' ),
        Field::inst( 'V_Rechnungern_mit_freig.freig_erledigt_wann' ),
        Field::inst( 'V_Rechnungern_mit_freig.freig_abl_grund' ),
        Field::inst( 'V_Rechnungern_mit_freig.freig_zahlsperre' ),
        Field::inst( 'V_Rechnungern_mit_freig.freig_zahlsp_grund' )
    )

    ->where( function ( $q, $freig_person ) {
        $q ->where( 'V_Rechnungern_mit_freig.buha_ok', 1 )
            ->where( 'V_Rechnungern_mit_freig.max', 10, '<' )
            ->where( 'V_Rechnungern_mit_freig.freig_erledigt', '0')
            ->where( function($r, $freig_person) {
                $r ->where( 'V_Rechnungern_mit_freig.freig_person', $freig_person )
                    ->or_where( 'V_Rechnungern_mit_freig.freig_person2', $freig_person );
            });
    })


    ->debug(true)
    ->process( $_POST )
    ->json();

I get an error as result. aim would be to have a sql where like

"V_Rechnungern_mit_freig.buha_ok = 1 
AND  V_Rechnungern_mit_freig.max < 10 
AND V_Rechnungern_mit_freig.freig_erledigt = 0 
AND (V_Rechnungern_mit_freig.freig_person = 3 OR V_Rechnungern_mit_freig.freig_person2 = 3)   

(assuming $freig_person is 3)

Do you see an error?

Thanks
Max

Replies

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    ->where( function ( $q, $freig_person ) {
    

    And it's friend for the $r parameter are incorrect. The where() method only takes a single parameter. I think you mean:

    ->where( function ( $q ) use ( $freig_person ) {
    

    (and again for $r)

    Allan

  • MadMax76MadMax76 Posts: 149Questions: 33Answers: 1

    thanks - works!

Sign In or Register to comment.