Call to undefined method app\models\User::instance() setting up kartik export yii2

时间:2019-05-31 12:22:31

标签: yii2 kartik-v

Trying to set up kratik grid export in Yii after doing everything I keep getting

Call to undefined method app\models\User::instance()

here is my code

$exportedValues = [['class' => 'kartik\\grid\\SerialColumn'], ['attribute' => 'deduction_date'], ['attribute' => 'deduction_amount'], ['attribute' => 'deduction_remark'], ['class' => 'kartik\\grid\\ActionColumn']];
$export = ExportMenu::widget(['dataProvider' => $dataProvider, 'columns' => $exportedValues, 'noExportColumns' => [0, 3], 'columnSelectorOptions' => ['label' => 'Columns', 'class' => 'btn btn-danger'], 'target' => '_blank', 'fontAwesome' => true, 'dropdownOptions' => ['label' => 'Export', 'class' => 'btn btn-success']]);

  echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 
  'columns' => [['class' => 'yii\\grid\\SerialColumn'], 
  'first_name', 'last_name', 'email_id', 'phone', ['class' => 'yii\\grid\\ActionColumn']]]); ?>

2 个答案:

答案 0 :(得分:0)

尝试安装kartik,或检查您的kartik版本

php composer.phar需要kartik-v / yii2-widgets“ *”

答案 1 :(得分:0)

有同样的问题。 在我替换的ExportMenu.php的源代码上:

$model = $modelClass::instance();

作者:

$model = new $modelClass;

为我解决了。