phreak, on 08 April 2011 - 10:08 AM, said:
you dont need to render a view, since you just create a file and send it to the user.
I dont know why you get that error, may be because of autoloading conflict.
Show me the code of your controller/action so i can help you.
btw compact('param') i just a way of writing array('param'=>$param)
It's realy quite a basic ext still, so it needs more work
but thanks for using it.
...my code
view
<?php $this->widget('zii.widgets.CMenu', array(
'encodeLabel'=>false,
'htmlOptions'=>array(
'class'=>'actions'),
'items'=>array(
array(
'label'=>'<img align="absmiddle" alt = "'.Yii::t('internationalization','Create'). '" src = "'.bUrl().'/images/icons/application_add.png" />'. ' ' . Yii::t('internationalization', 'Create'),
'url'=>array('Lectivo/create'),
),
array(
'label'=>'<img align="absmiddle" alt = "'.Yii::t('internationalization','Excel'). '" src = "'.bUrl().'/images/icons/disk.png" />'. ' ' . Yii::t('internationalization', 'Excel'),
'url'=>array('Lectivo/toExcel'),
),
array(
)
));
?>
<?php
$pageSize=Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']);
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'lectivo-grid',
'dataProvider'=>$model->search(),
'cssFile'=> bUrl().'/css/gridview/gridview.css',
'filter'=>$model,
'pager' => array(
'nextPageLabel' => 'Siguiente',
'prevPageLabel' => 'Anterior',
'firstPageLabel' => 'Primero',
'lastPageLabel' => 'Último',
'header' => '',
'maxButtonCount' => 5,
'cssFile' => bUrl().'/css/pagination/pagination.css'
),
'columns'=>array(
array(
'class'=>'CCheckBoxColumn',
),
array(
'name' => 'id_lectivo',
'header' => 'ID',
'filter'=>false,
'htmlOptions'=>array('align'=>'center')
),
'nombre',
'abreviatura',
array(
'name' => 'fec_inicio',
'value' => 'UtilFechas::aFechaNormal($data->fec_inicio)',
'htmlOptions'=>array('align'=>'center','style'=>'width: 103px;'),
'filter'=>$this->widget('zii.widgets.jui.CJuiDatepicker', array(
'model'=>$model,
'attribute'=>'fec_inicio',
'language'=>'es',
'htmlOptions'=>array('style'=>'width: 80px;'),
'options' => array(
'dateFormat' => 'yy-mm-dd',
'changeYear' => true,
'showOn' => 'button',
'buttonImage' => bUrl() . '/images/icons/calendar.png',
'buttonImageOnly' => true
)
), true),
),
array(
'name' => 'fec_fin',
'value' => 'UtilFechas::aFechaNormal($data->fec_fin)',
'htmlOptions'=>array('align'=>'center','style'=>'width: 103px;'),
'filter'=>$this->widget('zii.widgets.jui.CJuiDatepicker', array(
'model'=>$model,
'attribute'=>'fec_fin',
'language'=>'es',
'htmlOptions'=>array('style'=>'width: 80px;'),
'options' => array(
'dateFormat' => 'yy-mm-dd',
'changeYear' => true,
'showOn' => 'button',
'buttonImage' => bUrl() . '/images/icons/calendar.png',
'buttonImageOnly' => true
)
), true),
),
array(
'name' => 'estado',
'value' => '$data->estado',
'htmlOptions'=>array('align'=>'center'),
'filter'=>array('1'=>1,'0'=>0),
),
array(
'class'=>'CButtonColumn',
'header'=>CHtml::dropDownList('pageSize',
$pageSize,
array(10=>10,20=>20,50=>50),
array('onchange'=>"$.fn.yiiGridView.update('lectivo-grid',{ data:{pageSize: $(this).val() }})",)
),
),
),
'afterAjaxUpdate'=>'function(){
jQuery("#'.CHtml::activeId($model, 'fec_inicio').'").datepicker({
dateFormat: \'yy-mm-dd\',
changeYear: true,
showOn: \'button\',
buttonImage:\''.bUrl().'/images/icons/calendar.png\',
buttonImageOnly: true
});$.datepicker.setDefaults($.datepicker.regional["es"]);
jQuery("#'.CHtml::activeId($model, 'fec_fin').'").datepicker({
dateFormat: \'yy-mm-dd\',
changeYear: true,
showOn: \'button\',
buttonImage:\''.bUrl().'/images/icons/calendar.png\',
buttonImageOnly: true
});$.datepicker.setDefaults($.datepicker.regional["es"]);
}',
));
?>
this code is generated by gii-CRUD generator and I add some modifications The dataprovider of the grid is $model->search() for the filter
Controller
public function actiontoExcel() {
$this->widget('application.extensions.EExcelView', array(
'dataProvider'=> $DATA
));
Yii::app()->end();
}
In this case how to pass the $DATA value from the view to export it to excel??
and I get the error
Fatal error: Call to a member function search() on a non-object in C:\wamp\www\kelvin\protected\controllers\LectivoController.php on line 72
I try in the controler with
$model=new Lectivo('search');
$this->widget('application.extensions.EExcelView', array(
'dataProvider'=> $model->search(),
));
Yii::app()->end();
and the excel file exported not show the Grid, only the page without js and css
I'm still without export to excel
How can I fix this??
regards