view - How can I get the value from method in my model? -
i have trouble displaying result method in model. method:
/** * @return \yii\db\activequery */ public function getschoolfee() { return $this->hasone(sibuschool::classname(), ['school_fee_id' => 'school_fee_id']); } /** * @return \yii\db\activequery */ public function getscholarshipfee() { return $this->hasone(sibuscholarship::classname(),['scholarship_id'=>'scholarship_id']); } /** * @return \yii\db\activequery */ public function getdiscountfee() { $scholarship= $this->getscholarshipfee(); $school= $this->getschoolfee(); $data= new sibupayment(); $data->total_payment=$school->amount-($scholarship->school_discount*$school->amount); return $data; }
i want display result getdiscountfee method. use code on view:
<?php echo $this->render('_search3', ['model' => $searchmodel]); ?> <?= gridview::widget([ 'dataprovider' => $dataprovider, // 'filtermodel' => $searchmodel, 'columns' => [ [ // 'filtermodel'=>'dataprovidersearch', 'attribute' => 'nama', 'value' => 'virtual.student_name' ], [ 'attribute' => 'uang sekolah', 'value' => 'discountfee.total_payment' ], [ 'attribute' => 'uang kantin', 'value' => 'canteenfee.total_amount' ], [ 'attribute' => 'uang asrama', 'value' => 'dormitoryfee.amount' ], [ 'attribute' => 'uang perpustakaan', 'value' => 'libraryfee.amount' ], [ 'attribute' => 'uang les', 'value' => 'coursefee.amount' ], [ 'attribute' => 'adm. bank', 'value' => 'administration' ], [ 'attribute' => 'status', 'value' => function ($model) { if ($model->scholarship_id == 0) { return 'tanpa beasiswa'; } else if ($model->scholarship_id == 1) { return 'beasiswa ekonomi kategori 100%'; } else if ($model->scholarship_id == 2) { return 'beasiswa ekonomi kategori b 50%'; } else if ($model->scholarship_id == 3) { return 'beasiswa prestasi kategori 50%'; } else if ($model->scholarship_id == 4) { return 'beasiswa prestasi kategori 25%'; } else { return 'beasiswa prestasi kategori 10%'; } }, ], //'payment_class', [ 'attribute' => 'payment_class', 'value' => function ($model) { if ($model->payment_class == 0) { return 'tanpa golongan'; } else if ($model->payment_class == 1) { return 'golongan 1'; } else if ($model->payment_class == 2) { return 'golongan 2'; } else if ($model->payment_class == 3) { return 'golongan 3'; } else if ($model->payment_class == 4) { return 'golongan 4'; } }, ], [ 'attribute' => 'total', 'value' => 'total_payment' ], ['class' => 'yii\grid\actioncolumn', 'template' => '{update_r}{del}', 'buttons' => [ 'update_r' => function ($url, $model) { return html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [ 'title' => yii::t('yii', 'view_r'), ]); }, 'del' => function ($url, $model) { return html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [ 'title' => yii::t('yii', 'del'), ]); }, ] ], ], ]); ?>
it works fine if display this:
[ 'attribute' => 'uang sekolah', 'value' => 'scholarshipfee.school_discount' ],
and this:
[ 'attribute' => 'uang sekolah', 'value' => 'schoolfee.amount' ],
can me? if need feel free ask.
[ 'attribute' => 'uang sekolah', 'value' => 'discountfee.total_payment' ],
discountfee function of model, never work until put there model too. can
[ 'attribute' => 'uang sekolah', 'value' => function ($model) { return $model->getdiscountfee()->total_payment; } }, ],
Comments
Post a Comment