Yii2 Unknown Property Exception in Server - php

I have a view displaying a grid view for a particular model. In my local machine, it's working well but when I deploy the application to another server, an attribute is not found hence the Unknown Property Exception. When I look at the code though, the attribute is there.
Any ideas?
Here is the model class code: http://codebin.org/view/f0a713c1
The view code:
echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
[
'attribute' => 'is_condemned',
'label' => 'Condemned',
'class' => '\kartik\grid\BooleanColumn',
'falseLabel' => 'Active',
'trueLabel' => 'Condemned'
],
],
// set your toolbar
'toolbar' => [
['content' =>
Html::a(FA::icon('plus') . ' Add', ['/equipment/default/create'], ['class' => 'btn btn-success'])
],
'{export}',
'{toggleData}',
],
// set export properties
'export' => [
'fontAwesome' => true,
'filename' => 'equipment-export-'.time(),
'exportConfig' => [
'html' => ['showCaption' => FALSE],
'pdf' => ['showCaption' => FALSE],
],
],
'bordered' => TRUE,
'striped' => TRUE,
'condensed' => TRUE,
'responsive' => TRUE,
'hover' => TRUE,
'showPageSummary' => TRUE,
'panel' => [
'type' => GridView::TYPE_PRIMARY,
'heading' => '',
],
'persistResize' => false,
]);

The reason why it wasn't working was that the model class being imported was in lowercase. Apparently, I entered the wrong value in gii. It was just in the other servers that it was case-sensitive.

Could be either a problem with case (Uppercase, lowercase) in the namespace or in the class name or backslash path problem (/, \). In this case the class is not found and Yii shows this message.

Related

Yii2 - dropDownList filter outside GridView

I have a kartik\GridView in the view,
GridView
Actually, added a dropDownList on the toolbar
GridView with dropdownlist
But I need the dropDownList as a filter option for status [solicitudes_status], how can I achieve that?. Thank you.
$statusAll = TblEstatus::find()->all();
$statusArray = ArrayHelper::map($statusAll, 'estatus_id', 'estatus_descripcion');
$searchModel = new TblSolicitudesSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'solicitudes_solicitud',
'solicitudes_dependencia_destino_id',
'solicitudes_dependencia_tipoapoyo_id',
'solicitudes_status',
[
'attribute' => 'solicitudes_status',
'filter' => [ 1=>"Nuevos", 2=>"Atendiendo", 3=>"Terminados" ]
],
['class' => 'yii\grid\ActionColumn'],
],
'toolbar' => [
['content'=>
Html::dropDownList('status_list_drop', 'null', $statusArray, ['data-pjax'=>0, 'class' => 'form-control']),
],
],
'pjax' => true,
'bordered' => true,
'striped' => false,
'condensed' => false,
'responsive' => true,
'hover' => true,
'floatHeader' => false,
'showPageSummary' => false,
'panel' => [
'type' => GridView::TYPE_DEFAULT
],
]); ?>
You can try to use activeDropDownList to perform filtering:
Html::activeDropDownList($searchModel, 'attribute_name',
ArrayHelper::map(ModelName::find()->asArray()->all(), 'ID', 'Name'),
['class'=>'form-control','prompt' => 'Select status']),
Change values according to your attributes.

Yii2 GridView CheckboxColumn

I have a working Yii2 application locally with GridView but immediately I deployed it online, I started having issues with it. Below is the error and the code for the GridView:
ReflectionException Class \kartik\grid\checkBoxColumn does not exist
View File
use kartik\grid\GridView;
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'options' => [
'class' => 'table table-responsive'
],
'columns' => [
['class' => 'kartik\grid\checkBoxColumn'],
[
'class' => 'kartik\grid\ActionColumn',
'header' => 'Actions',
'headerOptions' => ['width' => '40'],
'template' => '{view} {update}'
],
],
]); ?>
I have tried to upgrade the version of the Yii2 application but yet I am still getting the same issue meanwhile everything is working fine locally.
it should be '\kartik\grid\CheckboxColumn' rather than '\kartik\grid\checkboxColumn' you must be working on windows locally the file names are case sensitive on unix.
change the below inside GridView
'columns' => [
['class' => 'kartik\grid\checkBoxColumn'],
to the following
'columns' => [
['class' => 'kartik\grid\CheckBoxColumn'],

Show summary row and add it to the end of excel export

I'm trying to create summary row for my GridView which sums my quantity for current page and for all records seperately.
<?= GridView::widget([
'dataProvider' => $dataProvider,
'layout' => "{summary}\n{items}\n<div align='right'>{pager}</div>",
//'filterModel' => $searchModel,
'showPageSummary' => true,
'pageSummaryFunc' => GridView::F_SUM,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'class' => DataColumn::className(),
'attribute' => 'updated_at',
'format' => 'raw',
'value' => function ($model, $key, $index, $column){
return date('Y-m-d', $model->updated_at);
},
],
[
'label' => 'Ilość',
'attribute'=>'quantity',
'pageSummary' => true,
'value'=> function ($model, $key, $index, $column) {
return ($model->quantity) ? $model->quantity : '';
},
],
],
]); ?>
At the end i want to export sum for all records to my excel sheet at the bottom of my gridColumns. My export widget looks like:
$dataProviderAll->setSort([
'defaultOrder' => ['updated_at' => SORT_ASC]
]);
echo ExportMenu::widget([
'container' => ['class' => 'btn-group pull-right', 'role' => 'group'],
'dataProvider' => $dataProviderAll,
'columns' => $gridColumns,
'filename' => date('Y-m-d') . '_raport',
'target' => ExportMenu::TARGET_SELF,
'showConfirmAlert' => false,
'showColumnSelector' => false,
'fontAwesome' => true,
'dropdownOptions' => [
'label' => 'Eksportuj dane',
'class' => 'btn btn-primary btn-md'
],
'exportConfig' => [
ExportMenu::FORMAT_HTML => null,
ExportMenu::FORMAT_TEXT => null,
ExportMenu::FORMAT_EXCEL => null,
ExportMenu::FORMAT_PDF => null
]
]);
?>
All columns of model are already exported, but i need to add summary row for some of them into created excel file.
Im getting now error like this: Setting unknown property: kartik\grid\GridView::pageSummaryFunc
Does someone know how can I get this result?
I have fixed part where I wanted to get sum per page by replacing class column from yii to kartik. –

Yii2 kartik datepicker multiple inline

I want a Datepicker inline with multidate enabled.
It is rendered correctly but returns only the last selected date.
Return value: '12.11.2016'
If I set 'type' to TYPE_INPUT everything is working fine.
Expected return Value: '23.11.2016, 24.11.2016, 18.11.2016, 12.11.2016'
<?= $form->field($model, 'dateString')->widget(DatePicker::className(), [
'type' => DatePicker::TYPE_INLINE,
'pluginOptions' => [
'multidate' => true,
],
]);
?>
I'm using "kartik-v/yii2-widget-datepicker": "#dev" and the model is a ActiveRecord Model.
Seems to have been fixed with this commit: https://github.com/kartik-v/yii2-widget-datepicker/commit/39e0e71277d0f115341e118a2b879a0dfcbd01c3
This will solve the problem
echo $form->field($model, 'date_time')->widget(DatePicker::classname(), [
'options' => [
'value' => "Jul-11-2020,Jul-14-2021,Jul-12-2020",
'class' => "col-md-12 form-control picker"
],
'readonly' => false,
'language' => 'en',
'type' => DatePicker::TYPE_INLINE,
'pluginOptions' => [
'format' => 'M-dd-yyyy',
'todayHighlight' => true,
'multidate' => true,
],
]);

Yii2: Kartik Gridview export config?

I am using Kartik Gridview. Export is also working fine, but summary data is not getting exported, but showing fine in the view.
As also I want to change the filename of the downloaded file.
I have tried this code, but nothing seems to be working
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => $gridColumns,
'showPageSummary' => true,
'exportConfig'=> [
GridView::EXCEL=>[
'filename' => Yii::t('kvgrid', 'Appointments'),
'showPageSummary' => true,
]
],
.....
That is I have added the export config in the gridview widget but it doesn't seems to be working.
What I am doing wrong here?
please suggest any changes.
try this
<?= ExportMenu::widget([
'dataProvider' => $dataProvider,
'columns' => $gridColumns,
'columnSelectorOptions'=>[
'label' => 'Columns',
'class' => 'btn btn-danger'
],
'fontAwesome' => true,
'dropdownOptions' => [
'label' => 'Export All',
'class' => 'btn btn-primary'
]
'exportConfig' => [
ExportMenu::FORMAT_HTML => false,
ExportMenu::FORMAT_TEXT => false,
],
]); ?>

Categories