我是Yii的新手,我已经安装了kartik导出扩展程序。当我以任何格式点击导出时,我没有收到任何错误,而是获得“生成导出文件。请稍候......”。我等了很多个小时,但我的过滤结果数据没有下载。
请检查我的代码:
public function actionProductivity()
{
$model = new EmployeeJobs();
$dataProvider = '';
if(isset($_GET['EmployeeJobs']))
{
$model->load(Yii::$app->request->get());
$strt='';
$from='';
$end ='';
$to ='';
$start = $model->start_date ;
$from = ( $start )? \DateTime::createFromFormat('d-m-Y', $start )->format('Y-m-d') : '';
$end = $model->end_date;
$to = ( $end )? \DateTime::createFromFormat('d-m-Y', $end )->format('Y-m-d') : '';
$sql ="SELECT employee.employee_name As Name,sum(distinct employee_jobs.sold_hour) As Sold_hour,
sum(distinct employee_jobs.actual_hour)As Actual_hr,
employee.id As emp_id,sum(distinct login_history.end_time) As login_hr,
(sum(distinct employee_jobs.sold_hour)/sum(distinct login_history.end_time)*100) As Productivity
FROM employee
LEFT OUTER JOIN employee_jobs ON employee_jobs.employee_id = employee.id
LEFT OUTER JOIN login_history ON login_history.employee_id = employee.id
WHERE employee_jobs.job_status>4
AND employee_jobs.sold_hour IS NOT NULL
";
if( $from != '')
{
$sql .= " AND employee_jobs.updated_time >= '{$from}' ";
$sql .= "AND login_history.logout_time >='{$from}'";
}
if($model->employee_id !='')
{
$sql.=" AND employee_jobs.employee_id={$model->employee_id}";
$sql.=" AND login_history.employee_id={$model->employee_id}";
}
if( $to != '')
{
$sql .= " AND employee_jobs.updated_time <= '{$to}' ";
$sql .= "AND login_history.logout_time <='{$to}'";
}
$sql .= " GROUP BY employee.id ";
$dataProvider = new SqlDataProvider([
'sql' => $sql,
]);
return $this->render('productivity_report',
[ 'model' => $model,
'dataProvider' => $dataProvider,
]);
}
视图/ productivity_report
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use app\models\Employee;
use yii\helpers\ArrayHelper;
use kartik\date\DatePicker;
use kartik\select2\Select2;
use yii\widgets\DetailView;
// use yii\grid\GridView;
use kartik\export\ExportMenu;
use kartik\grid\GridView;
/* @var $this yii\web\View */
/* @var $model app\models\EmployeeJobsSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="employee-jobs-search">
<?php $form = ActiveForm::begin([
'action' => ['productivity'],
'method' => 'get',
]); ?>
<h1> Productivity Report</h1>
<div class ="row">
<div class="col-md-3">
<?php
$data = ArrayHelper::map(Employee::find()->all(), 'id','employee_name');
echo $form->field($model, 'employee_id')->widget(Select2::classname(), [
'data' => $data,
'language' => 'de',
'options' => ['placeholder' => 'Select Employee ...'],
'pluginOptions' => [
'allowClear' => true
],
]);
?>
</div>
<div class="col-md-3">
<label> Start Date</label>
<?php
echo DatePicker::widget([
'model' => $model,
'attribute' => 'start_date',
'options' => ['placeholder' => 'Enter date '],
'pluginOptions' => [
'autoclose'=>true,
'format' =>'d-m-yyyy'
]
]);
?>
</div>
<div class="col-md-3">
<label>End Date </label>
<?php
echo DatePicker::widget([
'model' => $model,
'attribute' => 'end_date',
'options' => ['placeholder' => 'Enter date '],
'pluginOptions' => [
'autoclose'=>true,
'format' =>'d-m-yyyy'
]
]);
?>
</div>
</div>
<div class="form-group">
<?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?>
</div>
<div class="col-md-10">
<?php $gridColumns = [
['class' => 'kartik\grid\SerialColumn'],
'Name',
'Sold_hour',
['header'=>' Available Hour',
'value'=> function($data)
{
return round($data['login_hr'],2);
}
],
['header'=>'Productivity ',
'value'=> function($data)
{
return round($data['Productivity'],2);
}
],
];
?>
</div>
<?php
if( $dataProvider != '' ) :
echo ExportMenu::widget([
'dataProvider' => $dataProvider,
'columns' => $gridColumns,
'fontAwesome' => true,
'dropdownOptions' => [
'label' => 'Export All',
'class' => 'btn btn-default'
]
]) . "<hr>\n".
GridView::widget([
'dataProvider' => $dataProvider,
'columns' => $gridColumns,
]);
endif;
?>
<?php ActiveForm::end(); ?>
</div>
请帮帮我......