Editor alias for same table name?

Editor alias for same table name?

robert14robert14 Posts: 2Questions: 1Answers: 0
edited January 2019 in Free community support

I have this code in editor:

the problem is that it says i have same name for 'zcv_orders_details.data', can i set an alias or something?

Field::inst( 'zcv_orders_details.data' )->getFormatter( function ( $val, $data ) { return date( 'H:i d-m-Y', $val);})

Field::inst( 'zcv_orders_details.data' )->getFormatter( function ( $val, $data ) { return date( 'd-m-Y', $val);})

Full code:

// Build our Editor instance and process the data coming from _POST
$editor = Editor::inst( $db, 'zcv_orders_details', 'zcv_orders_details.id' )
    ->fields(
        Field::inst( 'zcv_orders_details.id' ),
        Field::inst( 'zcv_clients.firstname' ) ->validator( 'Validate::notEmpty' ),
        Field::inst( 'zcv_clients.lastname' ) ->validator( 'Validate::notEmpty' ),
        Field::inst( 'zcv_orders_details.data' )->getFormatter( function ( $val, $data ) { return date( 'H:i d-m-Y', $val);})
        Field::inst( 'zcv_orders_details.data' )->getFormatter( function ( $val, $data ) { return date( 'd-m-Y', $val);})
    )

     ->leftJoin( 'zcv_clients', 'zcv_clients.id', '=', 'zcv_orders_details.clients' );


     if(isset($_POST['year'])){
     $editor->where( 'FROM_UNIXTIME(zcv_orders_details.data, "%Y")', $_POST['year']);

     }
     if(isset($_POST['month'])){
    $editor->where( 'FROM_UNIXTIME(zcv_orders_details.data, "%c")', $_POST['month']);

     }
     if(isset($_POST['sala'])){
    $editor->where( 'zcv_orders_details.gyms', $_POST['sala']);

     }

     $editor
    ->process( $_POST )
    ->json();

Any idea is really apreciates.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    Answer ✓

    Hi,

    What you would need to do in this case is get the field just once with the full formatting (i.e. line 7 in your code above) and then on the client-side use a renderer to split that string and return just the date part if you want to show only that in a given column.

    Allan

  • robert14robert14 Posts: 2Questions: 1Answers: 0

    thank you Alan, the solution was great!

This discussion has been closed.