yii2如何显示更高的值

How to display a higher value yii2

如何显示更高的值,例如,如果mass > volumemass price出现在gridview中,如果mass < volumevolume price出现。 我这样用源码还是不行

    [
        'label' => 'Tarif',
        'format' => 'Currency',
        'value' => function ($model) {
            if ($volume= $model['rate'] * Yii::$app->request->get('TarifCargoSearch')['panjang'] * Yii::$app->request->get('TarifCargoSearch')['lebar'] * Yii::$app->request->get('TarifCargoSearch')['tinggi'] / 4000)
                return $volume;
            else if ($mass= $model['rate'] * Yii::$app->request->get('TarifCargoSearch')['massa'])
                return $mass;
            else if ($volume > $mass)
                return $volume;
            else if ($volume < $mass)
                return $mass;
        }
    ],
[
    'label' => 'Tarif',
    'format' => 'Currency',
    'value' => function ($model) {
        $volume = $model['rate'] * Yii::$app->request->get('TarifCargoSearch')['panjang'] * Yii::$app->request->get('TarifCargoSearch')['lebar'] * Yii::$app->request->get('TarifCargoSearch')['tinggi'] / 4000;
        $mass = $model['rate'] * Yii::$app->request->get('TarifCargoSearch')['massa'];

        return $mass > $volume? $mass : $volume;
    }
],

检查一下并告诉我,请确保您的计算正确。

已编辑

[
    'label' => 'Tarif',
    'format' => 'Currency',
    'value' => function ($model) {
        // Please note that the $model will be object not an array
        $volume = $model->rate * Yii::$app->request->get('TarifCargoSearch')['panjang'] * Yii::$app->request->get('TarifCargoSearch')['lebar'] * Yii::$app->request->get('TarifCargoSearch')['tinggi'] / 4000;
        $mass = $model->rate * Yii::$app->request->get('TarifCargoSearch')['massa'];

        return $mass > $volume? $mass : $volume;
    }
],

确保你的计算是正确的。参考https://www.yiiframework.com/doc/guide/2.0/en/output-data-widgets