M
M
Michael2019-04-18 23:08:44
Yii
Michael, 2019-04-18 23:08:44

How to display the received data in one of the fields in the GridView?

Hello everybody! I will briefly describe the nonsense below, in this code I search for accept_id from the orderitems table that correspond to the id in the accept table, in order to then display the order_id document number, there can be a maximum of two document numbers and no more. The code as a whole is working, I get document numbers, but I don’t know how to draw a conclusion, in this case only one document number is displayed, instead of two numbers, I understand that the point is that this is due to the two specified return, but I I don’t know how to do it differently anymore, the echo statement for each of the lines is not suitable, because displays the data above the gridview, not in the table cell.

[
  'label' => '',
  'attribute' => 'chek',
  'value' => function($data){           		
    $var1 = $data->orderitems;
    foreach ($var1 as $znach1) {
      $accept[] = $znach1->accept_id;
      $orders[] = $znach1->order_id;
    }
    return $data->id == $accept[0] ? Html::a(Html::encode($orders[0] . ', '), ['order/view', 'id' => $orders[0]]) : '';
    return $data->id == $accept[1] ? Html::a(Html::encode($orders[1]), ['order/view', 'id' => $orders[1]]) : '';
  },
  'format' => 'html',
],

I rewrote the code as follows, but somehow it didn’t help me either
foreach ($var1 as $key => $value) {
  $accept[] = $value->accept_id;
  $orders[] = $value->order_id;
  return $data->id == $accept[$key] ? Html::a(Html::encode($orders[$key] . ', '), ['order/view', 'id' => $orders[$key]]) : '';
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Moses Fender, 2019-04-19
@Bally

The second return still doesn't work. So then string concatenation exists for that.

return ($data->id == $accept[0] ? Html::a(Html::encode($orders[0] . ', '), ['order/view', 'id' => $orders[0]]) : '')
    . ($data->id == $accept[1] ? Html::a(Html::encode($orders[1]), ['order/view', 'id' => $orders[1]]) : '');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question