Jump to content

Yii Framework Eexcelview Extension


scarezekiel

Recommended Posts

Im trying to implement this extension but I seem dont know how to do it.. Can any Yii gurus help me..

 

im trying to use the extension eexcelview.. i need a button on my admin page that can export the results to excel

 

 

this is my controller

 

 


<?php

class MemberController extends Controller
{
/**
* @var string the default layout for the views. Defaults to '//layouts/column2', meaning
* using two-column layout. See 'protected/views/layouts/column2.php'.
*/
public $layout='//layouts/column2';

/**
* @return array action filters
*/
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
);
}

/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','view','loadImage'),
'users'=>array(@AuthorizationController::getRights('member', 'canview')),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('create'),
'users'=>array(@AuthorizationController::getRights('member', 'cancreate')),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('delete'),
'users'=>array(@AuthorizationController::getRights('member', 'candelete')),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('update'),
'users'=>array(@AuthorizationController::getRights('member', 'canupdate')),
),
array('deny',  // deny all users
'users'=>array('*'),
),
);
}


/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}

/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model=new member;

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

if(isset($_POST['member']))
{ 

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

       /*    
if(!empty($_FILES['member']['tmp_name']['binaryfile']))
           {

               $file = CUploadedFile::getInstance($model,'binaryfile');
               $model->filename = $file->name;
               $model->filetype = $file->type;
               $fp = fopen($file->tempName, 'r');
               $content = fread($fp, filesize($file->tempName));
               fclose($fp);
               $model->binaryfile = $content;

           }*/


           if($model->save())
           {
               $this->redirect(array('view','id'=>$model->id));
           }
}

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


/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{  
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

if(isset($_POST['member']))
{    
$model->attributes=$_POST['member'];

///$file = CUploadedFile::getInstance($model,'binaryfile');
   //$model->remark = $file;

           // if(!empty($_FILES['member']['tmp_name']['binaryfile']))
          // {
               //$file = CUploadedFile::getInstance($model,'binaryfile');

          /*  if( $file !== null )
            {
               $model->filename = $file->name;
               $model->filetype = $file;
               $fp = fopen($file->tempName, 'r');
               $content = fread($fp, filesize($file->tempName));
               fclose($fp);
               $model->binaryfile = $content;
            }*/
          // }

          // $model->user = Yii::app()->user->id;
           if($model->save())
           {    
               $this->redirect(array('view','id'=>$model->id));
           }
       }

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



/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'admin' page.
* @param integer $id the ID of the model to be deleted
*/
public function actionDelete($id)
{
if(Yii::app()->request->isPostRequest)
{
// we only allow deletion via POST request
$this->loadModel($id)->delete();

// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}

/**
* Lists all models.
*/
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('member');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}

/**
* Manages all models.
*/
public function actionAdmin()
{
$model=new member('search');
$model->unsetAttributes();  // clear any default values
if(isset($_GET['member']))
$model->attributes=$_GET['member'];

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

/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer the ID of the model to be loaded
*/
public function loadModel($id)
{
$model=member::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}

/**
* Performs the AJAX validation.
* @param CModel the model to be validated
*/
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='member-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}

public function actionloadImage($id)
   {
       $model=$this->loadModel($id);
       $this->renderPartial('picture', array(
           'model'=>$model
       ));
   }


}

 

 

 

this is my admin page

 



<?php
$this->breadcrumbs=array(
'Member Profile',
'Manage Member',
);

$this->menu=array(
//array('label'=>'List member', 'url'=>array('index')),
array('label'=>'Create Member', 'url'=>array('create')),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$.fn.yiiGridView.update('member-grid', {
data: $(this).serialize()
});
return false;
});
");
?>

<h1>Manage Members</h1>

<p>
You may optionally enter a comparison operator (<b><</b>, <b><=</b>, <b>></b>, <b>>=</b>, <b><></b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>

<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->




<?php 


$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'member-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(

 //'eno',
      // array( 'name'=>'membertypeid', 'value'=>'$data->membertype->code', 'htmlOptions'=>array('width'=>'40px'), ),
         array( 'name'=>'membertypeid',  
          'value'=>'$data->membertype->code',
//'value' => '$data->ismassbilling?Yii::t(\'app\',\'Yes\'):Yii::t(\'app\', \'No\')',
'filter' => array('AF' => Yii::t('app', 'AF'), 'CREN' => Yii::t('app', 'CR'),'OM' => Yii::t('app', 'OM')),
'htmlOptions'=>array('width'=>'80px'), ),  
       array( 'name'=>'membercode', 'value'=>'$data->membercode', 'htmlOptions'=>array('width'=>'70px'), ),




       array( 'name'=>'name', 'value'=>'$data->name', 'htmlOptions'=>array('width'=>'200px'), ),
         array( 'name'=>'icno', 'value'=>'$data->icno', 'htmlOptions'=>array('width'=>'150px'), ),
       //'passportno',

array( 'name'=>'state', 'value'=>'$data->state','htmlOptions'=>array('width'=>'50px'), ), 
       array( 'name'=>'companyid', 'value'=>'$data->company->companyname','htmlOptions'=>array('width'=>'120px'), ), 
     //  array( 'name'=>'statusid', 'value'=>'$data->status->statusid', ), 
array( 'name'=>'statusid', 'value'=>'$data->status->description','htmlOptions'=>array('width'=>'50px'), ), 
/*
       'id',
'joineddate',
'address1',
'address2',
'postcode',
'city',
'country',
'mobile1',
'mobile2',
'mobile3',
'tel1',
'tel2',
'tel3',
'fax1',
'fax2',
'fax3',
'email1',
'email2',
'email3',
'remark',
'picture',
'createdby',
'createddate',
'modifiedby',
'modifieddate',
*/
array
(
   'class'=>'CButtonColumn',
   'template'=>'{billing}{payment}{paymenthistory} {image}{status} {view}{update}{delete}',
   'htmlOptions'=>array('width'=>'300px'),
   'buttons'=>array
   (
       'billing' => array
       (
           'label'=>'Billing',
          'imageUrl'=>Yii::app()->request->baseUrl.'/themes/shadow_dancer/images/small_icons/invoice.png',
           'url'=>'"../billing/admin/".$data->id',
        //    'options'=>array('target'=>'_blank'),

       ),
         'payment' => array
       (
           'label'=>'Payment',
          'imageUrl'=>Yii::app()->request->baseUrl.'/themes/shadow_dancer/images/small_icons/bag.png',
           'url'=>'"../receivableledger/admin/".$data->id',
        //    'options'=>array('target'=>'_blank'),

       ),
            'paymenthistory' => array
       (
           'label'=>'Billing & Payment History',
          'imageUrl'=>Yii::app()->request->baseUrl.'/themes/shadow_dancer/images/small_icons/historyp.png',
           'url'=>'"../vwmember/view/".$data->id',
        //    'options'=>array('target'=>'_blank'),

       ),   
         'image' => array
       (
           'label'=>'Picture',
          'imageUrl'=>Yii::app()->request->baseUrl.'/themes/shadow_dancer/images/small_icons/page_white_picture.png',
          'url'=>'"../memberpicture/update/".$data->id',
         //   'options'=>array('target'=>'_blank'),
       ),

         'status' => array
       (
           'label'=>'Status Lookup',
          'imageUrl'=>Yii::app()->request->baseUrl.'/themes/shadow_dancer/images/small_icons/page_white_star.png',
          'url'=>'"../memberstatus/admin/".$data->id',
          //  'options'=>array('target'=>'_blank'),
       ),


   ),
),
),
)); ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.