Related
I have a gridview with pjax.
<div class="request-index">
<div id="ajaxCrudDatatable">
<?=
GridView::widget([
'id' => 'crud-datatable',
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'pjax' => true,
'columns' => require(__DIR__ . '/_columns.php'),
'toolbar' => [
['content' =>
Html::a('<i class="glyphicon glyphicon-plus"></i> Add Request', ['create'], ['role' => 'modal-remote', 'title' => 'Create new Requests', 'class' => 'btn btn-success']) .
Html::a('<i class="glyphicon glyphicon-repeat"></i> Reload', [''], ['data-pjax' => 1, 'class' => 'btn btn-primary', 'title' => 'Reset Grid']) .
'{toggleData}' .
'{export}'
],
],
'panel' => [
'type' => 'primary',
'heading' => '<i class="glyphicon glyphicon-list"></i> Requests listing',
'before' => '<button type="button" class="btn btn-danger btn-secondary"> Belum Selesai : <strong>'. $count_request_belum_selesai .'</strong> </button>',
'after' => BulkButtonWidget::widget([
'buttons' => Html::a('<i class="glyphicon glyphicon-trash"></i> Delete All', ["bulk-delete"], [
"class" => "btn btn-danger btn-xs",
'role' => 'modal-remote-bulk',delete this item'
]),
]) .
'<div class="clearfix"></div>',
]
])
?>
</div>
if you see from code above, please concern with
'before' => '<button type="button" class="btn btn-danger btn-secondary"> Not finished : <strong>'. $count_request_belum_selesai .'</strong> </button>',
When this button is clicked, I want to running a function in my model named RequestSearch :
public function searchRequestBelumSelesai(){
$query = Request::findAll(['tanggal_selesai' => NULL]);
return $query;
}
Which is the gridview will be displayed the result, is it possible ?
In the action of the controller that will receive the click of your button, you must modify the dataProvider given to the View, so that it looks like something like this:
$dataProvider= new ActiveDataProvider([
'query' => $your_model->searchRequestBelumSelesai(),
]);
I've tried for created form update using modal in yii2. The problem is every I change one field with the other value, the result form update with modal closed and redirect to index. And message update can't display in index. I don't know why, maybe wrong in code controller.
Code actionUpdate in controller
public function actionUpdate($id)
{
$model = CalonKeluargaAsuh::findOne($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->setFlash('success', 'Data berhasil diubah!');
return $this->redirect(['index']);
return $this->refresh();
} else {
if (Yii::$app->request->isAjax) {
return $this->renderAjax('update', ['model' => $model]);
}
else{
return $this->render('update', ['model' => $model]);
}
}
}
Code form in view
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\widgets\Pjax;
?>
<h2 align="center">Ubah Data Calon Keluarga Asuh</h2>
<?php
echo " ";
echo " ";
?>
<?php $form = ActiveForm::begin(['layout' => 'horizontal', 'enableAjaxValidation' => true,
'id' => 'update-form',
]); ?>
<?= $form->field($model, 'kode_calon_keluarga_asuh')->textInput(['readOnly' => true, 'style' => 'width:350px' ]) ?>
<?= $form->field($model, 'nama')->textInput(['style' => 'width:350px']) ?>
<?= $form->field($model, 'jenis_kelamin')->dropDownList(['Laki-laki' => 'Laki-laki', 'Perempuan' => 'Perempuan'],
['prompt'=>'--Pilih--', 'style' => 'width:350px']) ?>
<?= $form->field($model, 'pekerjaan')->textInput(['style' => 'width:350px']) ?>
<?= $form->field($model, 'alamat')->textArea(['rows' => 3, 'style' => 'width:350px']) ?>
<?= $form->field($model, 'telepon')->textInput(['style' => 'width:350px']) ?>
<div class="form-group">
<div class="col-sm-offset-4">
<?= Html::submitButton('Ubah', ['class' => 'btn btn-primary']) ?>
<?php
echo " ";
echo " ";
echo Html::a('Keluar', ['index'],[
'class'=>'btn btn-success',
'onclick' =>'$("#calonModal").modal("hide");
return false;'
]);
?>
<?php ActiveForm::end();?>
Code index.php in view
<?php \yii\widgets\Pjax::begin(['timeout' => false, 'id' => 'pjax-gridview']); ?>
<?php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use yii\bootstrap\Modal;
use yii\helpers\Url;
/* #var $this yii\web\View */
/* #var $searchModel app\models\SearchDonatur */
/* #var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Data Calon Keluarga Asuh';
?>
<?php if (Yii::$app->session->hasFlash('success')): ?>
<div class="alert alert-success alert-dismissable">
<button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
<h4><i class="icon fa fa-check"></i>Informasi!</h4>
<?= Yii::$app->session->getFlash('success') ?>
</div>
<?php endif; ?>
<?php if (Yii::$app->session->hasFlash('delete')): ?>
<div class="alert alert-success alert-dismissable">
<button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
<h4><i class="icon fa fa-check"></i>Informasi!</h4>
<?= Yii::$app->session->getFlash('delete') ?>
</div>
<?php endif; ?>
<div class="calon-keluarga-asuh-index">
<?php Pjax::begin(['timeout'=>false,'id'=>'pjax-gridview']); ?>
<h1><?= Html::encode($this->title) ?></h1>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a('Tambah Data', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'emptyCell' => '-',
'summary' => '',
'columns' => [
[
'attribute' => 'kode_calon_keluarga_asuh',
'value' => 'kode_calon_keluarga_asuh',
'contentOptions' => ['style' => 'width: 100px;']
],
[
'attribute' => 'nama',
'value' => 'nama',
'contentOptions' => ['style' => 'width: 250px;']
],
[
'attribute' => 'jenis_kelamin',
'value' => 'jenis_kelamin',
'contentOptions' => ['style' => 'width: 100px;']
],
[
'attribute' => 'pekerjaan',
'value' => 'pekerjaan',
'contentOptions' => ['style' => 'width: 200px;']
],
[
'attribute' => 'alamat',
'value' => 'alamat',
'contentOptions' => ['style' => 'width: 210px;']
],
[
'attribute' => 'telepon',
'value' => 'telepon',
'contentOptions' => ['style' => 'width: 100px;']
],
[
'class' => \yii\grid\ActionColumn::className(),
'header' => 'Aksi',
'template' => '{update} {delete}',
'buttons' => [
'update' => function($url, $model) {
$icon = '<span class="glyphicon glyphicon-pencil"></span>';
return Html::a($icon, $url,[
'data-toggle' => "modal",
'data-target' => "#calonModal",
]);
},
'delete' => function($url, $model) {
$icon = '<span class="glyphicon glyphicon-trash"></span>';
return Html::a($icon, $url,
[
'data-confirm' => "Apakah yakin dihapus ?",
'data-method' => 'post',
]);
},
]
],
],
]); ?>
<?php \yii\widgets\Pjax::end() ?>
<?php Pjax::end(); ?>
</div>
<?php
Modal::begin(['id' => 'calonModal']);
Pjax::begin(['id'=>'pjax-modal', 'timeout'=>false,
'enablePushState'=>false,
'enableReplaceState'=>false,]);
Pjax::end();
Modal::end();
?>
<?php
$this->registerJs('
$("#calonModal").on("shown.bs.modal", function (event) {
var button = $(event.relatedTarget)
var href = button.attr("href")
$.pjax.reload("#pjax-modal", {
"timeout":false,
"url":href,
"replace":false,
});
})
');
?>
Is it possible to put <style> tag inside and echo? My scenario is that I have a table of reimbursements and there's this "Type" column, where if the type is an "Ad Hoc Reimbursement", the whole table <tr>'s text color and font style will be changed:
And here's what it should look like:
I am using Yii 2.0 php framework. Here's my code:
echo GridView::widget([
'dataProvider' => $dataProvider,
//'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'header' => 'Employee ID',
'value' => 'employeeId'
],
[
'header' => 'Identification <br> Number',
'value' => 'IDnumber'
],
[
'header' => 'Employee <br> Name',
'format' => 'html',
'value' => 'fullName'
],
[
'header' => 'Attachment',
'format' => 'html',
'value' => function ($model) {
return !empty($model->attachment) ? Html::img($model->getImageUrl(), ['class' => 'reim-attach']): 'No Attachment';
},
],
[
'attribute' => 'receipt_company',
'header' => 'Merchant',
],
'description',
[
'attribute' => 'date',
'header' => 'Date <br><span style= "color:gray;font-size:8pt;"> (dd-mm-yyyy)</span>',
],
'currency',
[
'attribute' => 'amount',
'format'=>['decimal',2],
'value' => function ($model){
return !empty($model['amount']) ? $model['amount'] : 0.00;
}
],
[
'attribute' => 'exchange_rate',
'header' => 'Exchange <br> Rate',
'format'=>['decimal',2],
'value' => function ($model){
return !empty($model['exchange_rate']) ? $model['exchange_rate'] : 0.00;
}
],
[
'attribute' => 'converted_amount',
'header' => 'Converted <br> Amount',
'format'=>['decimal',2],
'value' => function ($model){
return !empty($model['converted_amount']) ? $model['converted_amount'] : 0.00;
}
],
[
'attribute' => 'chargeable',
'header' => 'Chargeable to <br> Client',
'value' => function ($model) {
return $model['chargeable'] ? 'Chargeable' : 'Non-chargeable';
},
],
[
'attribute' => 'date_noted',
'header' => 'Date Modified <br><span style= "color:gray;font-size:8pt;"> (dd-mm-yyyy)</span>',
],
[
'attribute' => 'status',
'label' => 'Status',
'content' => function ($model, $key, $index, $column) {
if ($model['status'] == "Pending") {
return Html::button('Pending', ['class' => 'status-pending']);
} elseif ($model['status'] == "Draft") {
return Html::button('Draft', ['class' => 'status-draft']);
} elseif ($model['status'] == "Approved") {
return Html::button('Approved', ['class' => 'status-approved']);
} elseif ($model['status'] == "Rejected") {
return Html::button('Rejected', ['class' => 'status-rejected']);
} elseif ($model['status'] == "Reimbursed") {
return Html::button('Reimbursed', ['class' => 'status-reimbursed']);
}
}
],
'type',
[
'label' => 'Action',
'content' => function ($model, $key, $index, $column) {
if($model['status'] == "Pending") {
return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view']).'&id=' . (string)$model['_id'], 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2', 'data-toggle'=>'tooltip', 'title'=>'View'])
.' '
.Html::button('<i class="fa fa-check-circle-o"></i> Approve', ['value' => $model['_id'], 'class' => 'btn btn-info btn-responsive', 'onclick'=>'approve(value)', 'data-toggle'=>'tooltip','title'=>'Approve'])
.' '
.Html::button('<i class="fa fa-ban"></i> Reject', ['value' => $model['_id'], 'class' => 'btn btn-danger btn-responsive', 'onclick'=>'reject(value)', 'data-toggle'=>'tooltip','title'=>'Reject']);
} elseif ($model['status'] == "Draft") {
return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view']).'&id=' . (string)$model->_id, 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2', 'data-toggle'=>'tooltip', 'title'=>'View'])
.' '
. Html::button('<span class="glyphicon glyphicon-pencil"></span>', ['value' => Url::to(['update']).'&id=' . (string)$model->_id, 'class' => 'btn btn-success btn-view btn-responsive','id' => 'modalButton3', 'data-toggle'=>'tooltip', 'title'=>'Update'])
.' '
. Html::a('<span class="glyphicon glyphicon-remove"></span>', ['delete', 'id' => (string)$model->_id], ['class' => 'btn btn-danger btn-responsive','data-toggle'=>'tooltip', 'title'=>'Delete', 'data' => ['confirm' => 'Are you sure you want to delete this reimbursement?', 'method' => 'post']]);
} elseif ($model['status'] == "Approved") {
if ($model->type == 'Ad Hoc Reimbursement') {
return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view']).'&id=' . (string)$model['_id'], 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2', 'data-toggle'=>'tooltip', 'title'=>'View'])
.' '
.Html::button('<i class="fa fa-check-square-o"></i> Reimburse', ['value' => $model['_id'], 'class' => 'btn btn-info btn-responsive', 'onclick'=>'reimburse(value)', 'data-toggle'=>'tooltip','title'=>'Reimburse']);
} else {
return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view']).'&id=' . (string)$model['_id'], 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2', 'data-toggle'=>'tooltip', 'title'=>'View'])
.' '
.Html::button('<i class="fa fa-check-circle-o"></i> Approve', ['value' => $model['_id'], 'class' => 'btn btn-default btn-responsive disable', 'onclick'=>'approve(value)', 'data-toggle'=>'tooltip', 'disabled' => true, 'title'=>'Approve'])
.' '
.Html::button('<i class="fa fa-ban"></i> Reject', ['value' => $model['_id'], 'class' => 'btn btn-default btn-responsive disable', 'onclick'=>'reject(value)', 'data-toggle'=>'tooltip', 'disabled' => true, 'title'=>'Reject']);
}
} else {
if ($model->type == 'Ad Hoc Reimbursement') {
echo "<style>.table-striped > tbody > tr { font-style: italic !important;color: #259A5A !important; }</style>";
return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view']).'&id=' . (string)$model['_id'], 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2', 'data-toggle'=>'tooltip', 'title'=>'View'])
.' '
.Html::button('<i class="fa fa-check-square-o"></i> Reimburse', ['value' => $model['_id'], 'class' => 'btn btn-default btn-responsive disable', 'onclick'=>'reimburse(value)', 'disabled' => true, 'data-toggle'=>'tooltip','title'=>'Reimburse']);
} else {
return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view']).'&id=' . (string)$model['_id'], 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2', 'data-toggle'=>'tooltip', 'title'=>'View'])
.' '
.Html::button('<i class="fa fa-check-circle-o"></i> Approve', ['value' => $model['_id'], 'class' => 'btn btn-default btn-responsive disable', 'onclick'=>'approve(value)', 'data-toggle'=>'tooltip', 'disabled' => true, 'title'=>'Approve'])
.' '
.Html::button('<i class="fa fa-ban"></i> Reject', ['value' => $model['_id'], 'class' => 'btn btn-default btn-responsive disable', 'onclick'=>'reject(value)', 'data-toggle'=>'tooltip', 'disabled' => true, 'title'=>'Reject']);
}
}
}
]
],
]);
In the last part, you can see the if ($model->type == 'Ad Hoc Reimbursement') and inside it, I put echo "<style>.table-striped > tbody > tr { font-style: italic !important;color: #259A5A !important; }</style>"; which I think is not right since it's NOT working.
Do you have any ideas about this?
You're applying conditional styling within your column configuration, which isn't going to work.
What you want to do is define the styling as a class, and conditionally change the row class in the <tr>
echo GridView::widget([
'dataProvider' => $dataProvider,
'rowOptions' => function ($model, $index, $widget, $grid){
return ['class'=> ($model->type == 'Ad Hoc Reimbursement') ? 'ad-hoc-reimbursement' : null];
},
]);
<style>
tr.ad-hoc-reimbursement {font-style: italic !important;color: #259A5A !important; }
</style>
I've researched a lot of problems like this but I can't seem to find the right solution for me. I am using Yii2 framework in PHP nad MongoDB for my database. I'm also using a Yii2 sortable extension for GridView and already installed it in my web application using composer.
Here's my GridView in my view:
<?php echo SortableGridView::widget([
'dataProvider' => $dataProvider,
//'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'code_type',
'payroll_name',
'cpf_type',
[
'label' => 'Action',
'content' => function ($model, $key, $index, $column) {
if ( ($model->company_id != null) && ($model->active == 1) ) {
if(in_array($model->payroll_name, array('Basic Salary', 'Overtime Pay', 'Daily/Hourly Wage', 'Commission', 'Bonus', 'Housing Allowance', 'Educational Allowance', 'Travel Allowance', 'Marriage Allowance', 'Leave Encashment', 'Reimbursement'))){
return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view-earnings']).'&id=' . (string)$model->_id, 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2']);
} else {
return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view-earnings']).'&id=' . (string)$model->_id, 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2'])
.' '
. Html::button('<span class="glyphicon glyphicon-pencil"></span>', ['value' => Url::to(['update-earnings']).'&id=' . (string)$model->_id, 'class' => 'btn btn-success btn-view btn-responsive','id' => 'modalButton3'])
.' '
. Html::a('<span class="glyphicon glyphicon-remove"></span>', ['delete-earnings', 'id' => (string)$model->_id], ['class' => 'btn btn-danger btn-responsive', 'data' => ['confirm' => 'Are you sure you want to delete this earnings item?', 'method' => 'post']])
.' '
. Html::button('Unset as Default', ['value' => (string)$model->_id, 'class' => 'btn btn-danger btn-responsive', 'onclick'=>'unset(value)']);
}
} else {
return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view-earnings']).'&id=' . (string)$model->_id, 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2'])
.' '
. Html::button('<span class="glyphicon glyphicon-pencil"></span>', ['value' => Url::to(['update-earnings']).'&id=' . (string)$model->_id, 'class' => 'btn btn-success btn-view btn-responsive','id' => 'modalButton3'])
.' '
. Html::a('<span class="glyphicon glyphicon-remove"></span>', ['delete-earnings', 'id' => (string)$model->_id], ['class' => 'btn btn-danger btn-responsive', 'data' => ['confirm' => 'Are you sure you want to delete this earnings item?', 'method' => 'post']])
.' '
. Html::button('Set as Default', ['value' => (string)$model->_id, 'class' => 'btn btn-info btn-responsive', 'onclick'=>'set(value)']);
}
}
]
],
'sortableAction' => Yii::$app->request->baseUrl . '/index.php?r=payroll-items/earnings-index'
]); ?>
Model:
public function behaviors()
{
return [
'sort' => [
'class' => SortableGridBehavior::className(),
'sortableAttribute' => 'sortOrder'
],
];
}
Controller:
public function actions()
{
return [
'sort' => [
'class' => SortableGridAction::className(),
'modelName' => PayrollItems::className(),
],
];
}
I found this problem but I don't know what to put inside updateworkshops.php (see top answer) since I am using MongoDB and not MySQL.
As in my current progress, I can only drag my GridView rows but the new order still can't be saved in my database.
Can somebody please explain to me how to do this?
I have a GridView where it displays data and one of them is an image. Here is my code in my GridView:
echo GridView::widget([
'dataProvider' => $dataProvider,
//'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'fullName',
[
'header' => '<a style="cursor: pointer;">Attachment</a>',
'format' => 'html',
'value' => function ($data) {
return Html::img($data->getImageUrl(), ['class' => 'reim-attach']);
},
],
'receipt_company',
'description',
'date',
'amount',
[
'attribute' => 'chargeable',
'value' => function ($model) {
return $model['chargeable'] ? 'Chargeable' : 'Non-chargeable';
},
],
'GST_amount',
'date_noted',
[
'attribute' => 'status',
'label' => 'Status',
'content' => function ($model, $key, $index, $column) {
if ($model['status'] == "Pending") {
return Html::button('Pending', ['class' => 'status-pending']);
} elseif ($model['status'] == "Draft") {
return Html::button('Draft', ['class' => 'status-pending']);
} elseif ($model['status'] == "Approved") {
return Html::button('Approved', ['class' => 'status-approved']);
} else {
return Html::button('Rejected', ['class' => 'status-rejected']);
}
}
],
[
'label' => 'Action',
'content' => function ($model, $key, $index, $column) {
if($model['status'] == "Pending") {
return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view']).'&id=' . (string)$model['_id'], 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2'])
.' '
.Html::button('<i class="fa fa-check-circle-o"></i> Approve', ['value' => $model['_id'], 'class' => 'btn btn-info btn-responsive', 'onclick'=>'approve(value)', 'data-toggle'=>'tooltip','title'=>'Approve', 'data' => [ 'confirm' => 'Are you sure you want to approve this reimbursement?', 'method' => 'post', ]])
.' '
.Html::button('<i class="fa fa-ban"></i> Reject', ['value' => $model['_id'], 'class' => 'btn btn-danger btn-responsive', 'onclick'=>'reject(value)', 'data-toggle'=>'tooltip','title'=>'Reject', 'data' => [ 'confirm' => 'Are you sure you want to reject this reimbursement?', 'method' => 'post', ]]);
} elseif($model['status'] == "Draft") {
return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view']).'&id=' . (string)$model['_id'], 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2'])
.' '
.Html::button('<i class="fa fa-check-circle-o"></i> Save Reimbursement', ['value' => $model['_id'], 'class' => 'btn btn-info btn-responsive', 'onclick'=>'saveReimbursement(value)', 'data-toggle'=>'tooltip','title'=>'Save Reimbursement', 'data' => [ 'confirm' => 'Are you sure you want to save this reimbursement?', 'method' => 'post', ]]);
} else {
return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view']).'&id=' . (string)$model['_id'], 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2'])
.' '
.Html::button('<i class="fa fa-check-circle-o"></i> Approve', ['value' => $model['_id'], 'class' => 'btn btn-default btn-responsive disable', 'onclick'=>'approve(value)', 'data-toggle'=>'tooltip','title'=>'Approve', 'data' => [ 'confirm' => 'Are you sure you want to approve this reimbursement?', 'method' => 'post', ]])
.' '
.Html::button('<i class="fa fa-ban"></i> Reject', ['value' => $model['_id'], 'class' => 'btn btn-default btn-responsive disable', 'onclick'=>'reject(value)', 'data-toggle'=>'tooltip','title'=>'Reject', 'data' => [ 'confirm' => 'Are you sure you want to reject this reimbursement?', 'method' => 'post', ]]);
}
}
]
],
]);
I get the following error on the line return Html::img($data->getImageUrl(), ['class' => 'reim-attach']):
Call to a member function getImageUrl() on a non-object
Here's a snippet of my controller:
$model = new Reimbursement();
$reimbursementQuery = new Query;
$reimbursementQuery->select([])->from('reimbursement')->andwhere(['company_id' => new \MongoId($session['company_id'])]);
if (isset(Yii::$app->request->getBodyParams()['period'])) {
if(Yii::$app->request->getBodyParams()['period'] != '') {
echo Yii::$app->request->getBodyParams()['period'];
$refreshData = true;
$selectedPeriodID = Yii::$app->request->getBodyParams()['period'];
$selectedPeriod = Periods::find()->where(['_id' => $selectedPeriodID])->one();
$reimbursementQuery->andWhere(['date_reimbursed' => array('$gte' => date('Y/m/d', strtotime($selectedPeriod->p_start)), '$lte' => date('Y/m/d', strtotime($selectedPeriod->p_end))) ]);
}
}
$reimbursements = $reimbursementQuery->all();
$dataProvider = new ArrayDataProvider([
'allModels' => $reimbursements,
]);
if($refreshData) {
return $this->renderPartial('_reports', [
'dataProvider' => $dataProvider,
]);
}
$dataProvider->pagination->pageSize = 10;
return $this->render('reports', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'model' => $model,
'rModel' => $rModel,
'employees' => $employees,
'contacts' => $contacts,
'periods' => $periods,
]); exit;
Here's also my model:
public function getImageUrl()
{
return Url::to('#web/' . $this->attachment, true);
}
Hope somebody could point out where I missed and how to get rid of the error.
Its happen because you access none data in database or you didnt specify your function. . .
[ 'header' => '<a style="cursor: pointer;">Attachment</a>', 'format' => 'html','value' => function ($data) {
$attachment = YourModel::find($model->yourId)->one()->attachment;
return Html::img(Url::to('#web/' . $attachment, true), ['class' => 'reim-attach']);
},
],