Hi I am trying to export a query to an excel file but I have not succeeded in this forum mime I found an example but I do not export anything just shows me what I leave the code acontinuacion
public function actionReporte() {
$bus = true;
if (!isset($_POST['fechaini']) || $_POST['fechaini'] == "") {
if (!isset($_POST['fechafin']) || $_POST['fechafin'] == "") {
$bus = false;
}
}
if ($bus == true) {
header('Content-type: text/csv');
header('Content-Disposition: attachment; filename="report-customers-' . date('YmdHi') . '.csv"');
$criteria = new CDbCriteria();
$criteria->addBetweenCondition("Fecha_cita", $_POST['fechaini'], $_POST['fechafin']);
$criteria->addCondition('personal="no"');
$citas = Calendario::model()->findAll($criteria);
Yii::app()->user->setState('exportModel',$citas);
if (Yii::app()->user->getState('exportModel'))
$citas = Yii::app()->user->getState('exportModel');
$dataProvider = new CArrayDataProvider($citas);
foreach ($dataProvider->getData() as $data) {
echo "$data->Fecha_cita, $data->Hora_inicial,
$data->Servicio, $data->Nombre_completo \r\n";
}
exit;
} else {
throw new CHttpException(500, 'Faltan Parametros');
}
}
and view
<div id="resultado">
<?php echo TbHtml::textField('fechaini', '', array("style" => "margin-bottom: 5px;")) . ' Hasta: ' . TbHtml::textField('fechafin', '', array("style" => "margin-bottom: 5px;")); ?>
<?php
echo TbHtml::submitButton(TbHtml::icon(TbHtml::ICON_DOWNLOAD_ALT) . 'Generar', array('color' => TbHtml::BUTTON_COLOR_WARNING,
"ajax" => array(
"type" => "post",
"url" => Yii::app()->createUrl("admin/calendario/reporte"),
"data" => array(
"fechaini" => "js:$('#fechaini').val()",
"fechafin" => "js:$('#fechafin').val()"
),
"success" => "function(data){
$('#reporte').html(data);
}",
"error" => "function(data){
$('#reporte').html('');
}",
)
))
?>
<?php echo CHtml::link('Excel', array('Excel'), array('class' => 'bt-excel')); ?>
<div id="reporte">
<?php $this->renderPartial('reporte'); ?>
</div>
</div>
thanks for the help you can give me