Export To Excel Consultation With Parameters

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

hi,

I could already export the excel file, but I need to pass url values ​​stuff to send to the query that generates the excel file I do not know how I can pass it values ​​URL (get)

Not sure why you need a url to generate an Excel file. Also where are you getting the url? But you could try




      "ajax" = > array(

            ...

            "data" => array(

                "fechaini" => "js:$('#fechaini').val()",

                "fechafin" => "js:$('#fechafin').val()",

                "url" => 'whatever/something.html"

            ),

            ...

      )