Hi…
Does anyone can give me an example how to export data from dataProvider CGridView using phpexcel, thank you
My Controller
public function actionAdmin()
{
$model=new Department('search');
if(isset($_GET['yt1']))
{
$dataProvider= $model->search();
$dataProvider->pagination= false; // for retrive all modules
$data = $dataProvider->data();
foreach ($data as $model)
{
$dudul = array($model);
}
$xls = new JPhpExcel('UTF-8', false, 'test');
$xls->addArray($dudul);
$xls->generateXML('my-test');
}
$this->render('admin',array(
'model'=>$model,
));
}
My View
<?php $eek=$this->beginWidget('CActiveForm', array(
'action'=>Yii::app()->createUrl($this->route),
'method'=>'get',
)); ?>
<div class="row buttons">
<?php echo CHtml::submitButton('export'); ?>
</div>
<?php $this->endWidget(); ?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'department-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'header'=>'No',
'value'=>'$this->grid->dataProvider->pagination->currentPage*$this->grid->dataProvider->pagination->pageSize+$row+1'
),
'department_name',
'employee',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
the output is
CException
Description
CActiveDataProvider does not have a method named "data".
Source File
C:\xampp\htdocs\yii\framework\base\CComponent.php(266)
00254: public function __call($name,$parameters)
00255: {
00256: if($this->_m!==null)
00257: {
00258: foreach($this->_m as $object)
00259: {
00260: if($object->getEnabled() && method_exists($object,$name))
00261: return call_user_func_array(array($object,$name),$parameters);
00262: }
00263: }
00264: if(class_exists('Closure', false) && $this->$name instanceof Closure)
00265: return call_user_func_array($this->$name, $parameters);
00266: throw new CException(Yii::t('yii','{class} does not have a method named "{name}".',
00267: array('{class}'=>get_class($this), '{name}'=>$name)));
00268: }
00269:
00270: /**
00271: * Returns the named behavior object.
00272: * The name 'asa' stands for 'as a'.
00273: * @param string the behavior name
00274: * @return IBehavior the behavior object, or null if the behavior does not exist
00275: * @since 1.0.2
00276: */
00277: public function asa($behavior)
00278: {
Stack Trace
#0 [internal function]: CComponent->__call('data', Array)
#1 C:\xampp\htdocs\diklat\protected\controllers\DepartmentController.php(175): CActiveDataProvider->data()
#2 C:\xampp\htdocs\yii\framework\web\actions\CInlineAction.php(50): DepartmentController->actionAdmin()
#3 C:\xampp\htdocs\yii\framework\web\CController.php(300): CInlineAction->run()
#4 C:\xampp\htdocs\yii\framework\web\filters\CFilterChain.php(133): CController->runAction(Object(CInlineAction))
#5 C:\xampp\htdocs\yii\framework\web\filters\CFilter.php(41): CFilterChain->run()
#6 C:\xampp\htdocs\yii\framework\web\CController.php(1049): CFilter->filter(Object(CFilterChain))
#7 C:\xampp\htdocs\yii\framework\web\filters\CInlineFilter.php(59): CController->filterAccessControl(Object(CFilterChain))
#8 C:\xampp\htdocs\yii\framework\web\filters\CFilterChain.php(130): CInlineFilter->filter(Object(CFilterChain))
#9 C:\xampp\htdocs\yii\framework\web\CController.php(283): CFilterChain->run()
#10 C:\xampp\htdocs\yii\framework\web\CController.php(257): CController->runActionWithFilters(Object(CInlineAction), Array)
#11 C:\xampp\htdocs\yii\framework\web\CWebApplication.php(324): CController->run('admin')
#12 C:\xampp\htdocs\yii\framework\web\CWebApplication.php(121): CWebApplication->runController('Department...')
#13 C:\xampp\htdocs\yii\framework\base\CApplication.php(135): CWebApplication->processRequest()
#14 C:\xampp\htdocs\diklat\index.php(13): CApplication->run()
#15 {main}