Upload And Store Date Excel File In Cgridview With Extension Jphpexcelreader

Hi guys, anyone can help me to solve my problem uploading excel file (xls, xlsx) with extension JPHPExcelReader. This is my table lba(id, campaign_id, campaign_name, target_location, status, customer, sender_id, start_periode, stop_periode, success, failed) and lba_upload[id, filename, request_by, date_created]. I couldn’t read data from uploaded file. This is my code in lba controller :

public function actionIndex()

{


	Yii::import("application.extensions.phpexcelreader.JPhpExcelReader");


	$model=new Excel;


	$filename = date("YmdHis") . rand(101, 999) . rand(1, 9) . rand(1001, 9999) . '.xls';


	if(isset($_POST['Excel']))


	{


		$model->attributes=$_POST['Excel'];


		$model->filename = $filename;


		$up=CUploadedFile::getInstance($model,'file');


		$model->file = $up;


		$path=Yii::app()->basePath.'/uploads/'.$filename.".xls";


		$up->saveAs($path);


		


	 if ($model->save()) {


		$data = new JPhpExcelReader($path);


		


		$campaign_id=array();


		$campaign_name=array();


		$target_location=array();


		$status=array();


		$customer=array();


		$sender_id=array();


		$start_periode=array();


		$stop_periode=array();


		$success=array();


		$failed=array();


		for ($j = 2; $j <= $data->sheets[0]['numRows']; $j++) 


		{


			


			if (empty($data->sheets[0]['cells'][$j][1]))


			continue;


			


			$campaign_id=$data->sheets[0]['cells'][$j][1];


			$campaign_name=$data->sheets[0]['cells'][$j][2];


			$target_location=$data->sheets[0]['cells'][$j][3];


			$status=$data->sheets[0]['cells'][$j][4];


			$customer=$data->sheets[0]['cells'][$j][5];


			$sender_id=$data->sheets[0]['cells'][$j][6];


			$start_periode=$data->sheets[0]['cells'][$j][7];


			$stop_periode=$data->sheets[0]['cells'][$j][8];


			$success=$data->sheets[0]['cells'][$j][9];


			$failed=$data->sheets[0]['cells'][$j][10];


		}


	


		for($i=0;$i<count($id);$i++)


		{


			$model=new Lba;





			


			$model->campaign_id=$campaign_id[$i];


			$model->campaign_name=$campaign_name[$i];


			$model->target_location=$target_location[$i];


			$model->status=$status[$i];


			$model->customer=$customer[$i];


			$model->sender_id=$sender_id[$i];


			$model->start_periode=$start_periode[$i];


			$model->stop_periode=$stop_periode[$i];


			$model->success=$success[$i];


			$model->failed=$failed[$i];


			$model->save();


                   }


                    //unlink($path);


					


		Yii::app()->db->createCommand("INSERT INTO lba(campaign_id,campaign_name,target_location,status,customer,sender_id,start_periode,stop_periode,success, failed)


		VALUES('$campaign_id','$campaign_name','$target_location','$status','$customer','$sender_id','$start_periode','$stop_periode','$success', '$failed') ")->execute();


		


	}


	$this->redirect(array('admin'));


	}


	$this->render('index',array('model'=>$model));


	spl_autoload_register(array('YiiBase','autoload'));


}

Excel Model :

<?php

class Excel extends CActiveRecord

{

public $file;

public function beforeSave() {





    &#036;this-&gt;date_created = new CDbExpression('NOW()');


    return parent::beforeSave();


}

public function tableName()

{


	return 'lba_upload';


}





public function rules()


{


	return array(


		array('filename', 'required'),


		array('filename', 'length', 'max'=&gt;1000),


		array('file','file','types'=&gt;'xls'),


		array('file','safe','on'=&gt;'index'),


		array('request_by', 'length', 'max'=&gt;30),


		array('id, filename, request_by, date_created', 'safe', 'on'=&gt;'search'),


	);


}





public function attributeLabels()


{


	return array(


		'id' =&gt; 'ID',


		'filename' =&gt; 'Filename',


		'request_by' =&gt; 'Request By',


		'date_created' =&gt; 'Date Created',


	);


}





public static function model(&#036;className=__CLASS__)


{


	return parent::model(&#036;className);


}

}

?>

Form upload (index.php) :

<?php

/* @var $this LbaController */

/* @var $dataProvider CActiveDataProvider */

$this->breadcrumbs=array(

'LBA',

);

$this->menu=array(

//array('label'=&gt;'Create Lba', 'url'=&gt;array('create')),


array('label'=&gt;'Manage LBA', 'url'=&gt;array('admin')),

);

?>

<h1>Upload</h1>

<div class="form">

<?php $form=$this->beginWidget(‘CActiveForm’, array(

'id'=&gt;'excel-form',


'enableAjaxValidation'=&gt;false,


    'htmlOptions'=&gt;array('enctype'=&gt;'multipart/form-data'),

)); ?>

&lt;div class=&quot;row&quot;&gt;


            &lt;b&gt;Upload :&lt;/b&gt;


	&lt;?php echo &#036;form-&gt;fileField(&#036;model,'file'); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model,'file'); ?&gt;


	


&lt;/div&gt;


&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'request_by'); ?&gt;


	&lt;?php echo &#036;form-&gt;textField(&#036;model,'request_by',array('size'=&gt;30,'maxlength'=&gt;30)); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model,'request_by'); ?&gt;


&lt;/div&gt;


&lt;div class=&quot;row&quot;&gt;


&lt;?php echo CHtml::submitButton(&#036;model-&gt;isNewRecord ? 'Upload' : 'Save'); ?&gt;


&lt;/div&gt;

<?php $this->endWidget(); ?>

</div>

View/admin.php :

<?php

/* @var $this LbaController */

/* @var $model Lba */

$this->breadcrumbs=array(

'LBA'=&gt;array('admin'),


'Manage',

);

$this->menu=array(

//array('label'=&gt;'List Lba', 'url'=&gt;array('index')),


array('label'=&gt;'Upload', 'url'=&gt;array('index')),

);

Yii::app()->clientScript->registerScript(‘search’, "

$(’.search-button’).click(function(){

&#036;('.search-form').toggle();


return false;

});

$(’.search-form form’).submit(function(){

&#036;('#lba-grid').yiiGridView('update', {


	data: &#036;(this).serialize()


});


return false;

});

");

?>

<h1>LBA Report</h1>

<!–<?php echo CHtml::link(‘Advanced Search’,’#’,array(‘class’=>‘search-button’)); ?>–>

<div class="search-form" style="display:visible">

<?php $this->renderPartial(’_search’,array(

'model'=&gt;&#036;model,

)); ?>

</div><!-- search-form -->

<div><?php

$imgpdf=CHtml::image(‘images/pdf.png’, ‘pdf’);

echo CHtml::link($imgpdf, array(‘lba/pdf’, ‘id’=>$model->id), array(“target”=>"_blank"));?>&nbsp;&nbsp;&nbsp;<?php

$imgpdf=CHtml::image(‘images/excel.png’, ‘excel’);

echo CHtml::link($imgpdf, array(‘lba/excel’, ‘id’=>$model->id), array(“target”=>"_blank"));?>&nbsp;&nbsp;&nbsp;<?php

$imgpdf=CHtml::image(‘images/csv.png’, ‘csv’);

echo CHtml::link($imgpdf, array(‘lba/csv’, ‘id’=>$model->id), array(“target”=>"_blank"));?></div>

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

'id'=&gt;'lba-grid',


'dataProvider'=&gt;&#036;model-&gt;search(),


'summaryText'=&gt;'',


//'filter'=&gt;&#036;model,


'columns'=&gt;array(


	array(


        'header'=&gt;'No.',


        'value'=&gt;'&#036;this-&gt;grid-&gt;dataProvider-&gt;pagination-&gt;currentPage * &#036;this-&gt;grid-&gt;dataProvider-&gt;pagination-&gt;pageSize + (&#036;row+1)',


    ),


	//'campaign_id',


	array(


		'name'=&gt;'campaign_name',


		'htmlOptions'=&gt;array('style'=&gt;'font-weight:bold; width:250px'),


		'value' =&gt; '&#036;data-&gt;campaign_name',


        'type'  =&gt; 'raw',


    ),


	//'target_location',


	//'status',


	//'customer',


	'sender.sender_id',


	'start_periode',


	array(


		'name'=&gt;'stop_periode',


		'footer'=&gt;'Total : ',


		'footerHtmlOptions'=&gt;array(


            'style'=&gt;'text-align: right; padding-right: 5px; font-weight: bold'


	),),


	array(


		'class'=&gt;'ext.gridcolumns.TotalColumn',


		'name'=&gt;'success',


		'htmlOptions'=&gt;array('style'=&gt;'font-weight:normal'),


		'output'=&gt;'Yii::app()-&gt;format-&gt;formatNumber(&#036;value)',


		'footer'=&gt;true,


		//'footer'=&gt;'Total : Rp. '.number_format(&#036;model-&gt;getTotals()),


		'footerHtmlOptions'=&gt;array(


            'style'=&gt;'text-align: right; padding-right: 5px; font-weight: bold'


	),),


	


	//'failed',


	//'date_created',


	/*array(


		'header'=&gt;'Action',


		'class'=&gt;'CButtonColumn',


	),


	*/


),

)); ?>

I want uploaded file’s data stored in table lba and viewed with Cgridview in admin.php. Anyone help??