AJAX validation in search - yii

I am new to Yii, I have two tables. master_customer,master_client. In the client model, in the view I have a search box, If I enter a few letters in the search box, it must automatically get the data and give results from master_customers(like google suggestions). I have made relations in the client model with the master_customer.
please help me with the code. Thanks in advance
CONTROLLER action:
public function actionIndex()
{
$criteria = new CDbCriteria();
if(isset($_GET['q']))
{
$q = "%".$_GET['q']."%";
$criteria->condition = 'cust_name='.$q;
$arrTier3 = MasterCustomers::model()->findAll($criteria);
//$criteria->compare(MasterCustomers::model()->cust_name,$q, true);
//$criteria->compare('$data->customers->cust_name', $q, true, 'OR');
print_r($arrTier3);
die();
}
$dataProvider=new CActiveDataProvider('Host', array('criteria'=>$criteria));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
view :
<!--Content-->
<div id="content">
<div style="padding: 10px;">
<a href="<?php echo $this->createUrl('/Controller/create');?>" title="Create New Host" class="btn btn-primary circle_ok" style="text-decoration: none;" >Add New Host to Customer</a>
<div style="float:right">
<?php
echo CHtml::link('Upload Customer CSV', array('/Controller/uploadCustomers'), array(
'onclick'=>'return hs.htmlExpand(this, { objectType: "iframe", wrapperClassName: "full-size", align: "center" } )',
'class'=>'btn btn-primary',
'id'=>'upload_link',
));
?>
</div>
</div>
<h3><?php echo $title; ?></h3>
<div class="innerLR">
<div class="row-fluid">
<?php
$obj=$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
//'afterAjaxUpdate'=>'\'changeTRColor()\'',
//'itemView'=>'_view',
'columns'=>array(
array( // display 'create_time' using an expression
'name'=>'name',
'value'=>'$data->host_name',
),
array(
'name'=>'serviceId',
'value'=>'$data->host_serviceid',
),
array(
'name'=>'customer',
'value'=>'$data->customers->cust_name',
),
array(
'class'=>'CButtonColumn',
'template'=>'{delete}{update}',)
),
));
?>
<form method="get">
<input type="search" placeholder="search" name="q" value="<?=isset($_GET['q']) ? CHtml::encode($_GET['q']) : '' ; ?>" />
<input type="submit" value="search" />
</form>
</div>
<div class="separator bottom"></div>
</div>
</div>
<!-- // Content END -->
<div class="clearfix"></div>
<!-- // Sidebar menu & content wrapper END -->
<div id="footer" class="hidden-print">
<?php $this->renderPartial('application.views.layouts._footer_inc'); ?>
</div>

If you need a search like google that searches on each key press and update GridView then you can try like this. In your javascript write
<script type="text/javascript">
$(document).ready(function () {
$('#id of your search box').keyup(function () {
$.fn.yiiGridView.update('id of your grid to be updated', {
data: $(this).serialize()
});
});
});
</script>
In your controller check the $_POST variable that what value it has, so you can grab that value and search in master_customers for that specific value and render the view again.

Related

how to Get cat id and expertise value in my controler

This is my controller and I am trying to get category id and expertise data from my database field. Everything is working, but the problem is that I'm not getting the category id. The problem occurs when I am trying to print all record on my view controller. here is my part of code $cat_id =Yii::$app->request->get('categori_id');.
//start premium adviser section
public function actionPremiumsearch()
{
if(isset($_GET['login-button1']))
{
$model=new UserDetail();
$request = Yii::$app->request;
$post = $request->get();
$cat_id =Yii::$app->request->get('categori_id');
//var_dump($cat_id);exit;
//print_r($cat_id);exit;
$expertise =Yii::$app->request->get('expertise');
//print_r($expertise);exit;
//var_dump($cat_id);exit;
//$cat = $request->cat_id();
//echo $cat;
//print_r($post);
//$cat_id = $request->get('categori_id');
//echo $cat_id;
//$cat_id = $post['categories']['categori_id'];
//echo $cat_id;exit;
//print_r($cat_id);exit;
//print_r($post);
//$cat_id = $post['categori_id'];
//print_r($cat_id);
//$service_id = $post['Service']['id'];
//echo $service_id.' '.$expertise.' '.$cat_id;
//exit;
//echo "button1";
$query = new Query;
// compose the query
$query->select('kpt_users.*,kpt_user_details.*,kpt_user_services.*')
->from('kpt_users')
->join( 'INNER JOIN',
'kpt_user_details',
'kpt_user_details.user_id =kpt_users.id'
)
->join( 'LEFT JOIN',
'kpt_user_services',
'kpt_user_services.user_id= kpt_users.id'
)
//->Where(['kpt_users.user_role_id' =>$role_id,'kpt_user_services.service_id'=>$service_id])
->Where('kpt_users.status = 1')
->andWhere('kpt_users.user_role_id = 2')
//->andFilterWhere(['like', 'kpt_user_services.service_id', $this->service_id])
//->andFilterWhere(['like', 'kpt_user_details.categori_id', $this->categori_id])
//->andFilterWhere(['like', 'kpt_user_details.expertise', $this->expertise])
//->andWhere(['like', 'kpt_user_services.service_id', $service_id])
//->andWhere(['like', 'kpt_user_details.categori_id', $categori_id])
// ->andWhere(['like', 'kpt_user_details.expertise', $expertise])
//->andWhere('kpt_user_details = 2')
//->andWhere(['like', 'categori_id', $cat_id])
//->andWhere(['like', 'name', 'alex'])
//->andWhere(['like','kpt_user_services.service_id'=>$service_id,'kpt_user_details.categori_id'=>$cat_id])
->limit(2);
// build and execute the query
$rows = $query->all();
//var_dump($rows);exit;
return $this->render('personalinsurance', [
'result' => $rows,
'model' => $model,
]);
}
if(isset($_GET['login-button2'])){
//echo "kanak";
//echo "button1";
$query = new Query;
// compose the query
$query->select('kpt_users.*,kpt_user_details.*,kpt_user_services.*')
->from('kpt_users')
->join( 'INNER JOIN',
'kpt_user_details',
'kpt_user_details.user_id =kpt_users.id'
)
->join( 'LEFT JOIN',
'kpt_user_services',
'kpt_user_services.user_id= kpt_users.id'
)
//->Where(['kpt_users.user_role_id' =>$role_id,'kpt_user_services.service_id'=>$service_id])
->limit(4);
// build and execute the query
$rows = $query->all();
//var_dump($rows);exit;
return $this->render('corporateinsurance', [
'result' => $rows,
]);
}
if(isset($_GET['login-button3'])){
//echo "kanak3";
//echo "button1";
$query = new Query;
// compose the query
$query->select('kpt_users.*,kpt_user_details.*,kpt_user_services.*')
->from('kpt_users')
->join( 'INNER JOIN',
'kpt_user_details',
'kpt_user_details.user_id =kpt_users.id'
)
->join( 'LEFT JOIN',
'kpt_user_services',
'kpt_user_services.user_id= kpt_users.id'
)
//->Where(['kpt_users.user_role_id' =>$role_id,'kpt_user_services.service_id'=>$service_id])
->limit(4);
// build and execute the query
$rows = $query->all();
//var_dump($rows);exit;
return $this->render('sbasedplanning', [
'result' => $rows,
]);
}
if(isset($_GET['login-button4'])){
// echo "kanak4";
//echo "button1";
$query = new Query;
// compose the query
$query->select('kpt_users.*,kpt_user_details.*,kpt_user_services.*')
->from('kpt_users')
->join( 'INNER JOIN',
'kpt_user_details',
'kpt_user_details.user_id =kpt_users.id'
)
->join( 'LEFT JOIN',
'kpt_user_services',
'kpt_user_services.user_id= kpt_users.id'
)
//->Where(['kpt_users.user_role_id' =>$role_id,'kpt_user_services.service_id'=>$service_id])
->Where(['kpt_users.user_role_id' =>$role_id,'kpt_user_details.categori_id'=>$category_id])
->limit(4);
// build and execute the query
$rows = $query->all();
//var_dump($rows);exit;
return $this->render('taxplanning', [
'result' => $rows,
]);
}
}
This is my view controller with the foreach-loop. When I am trying to print the record, the category ID is missing. How can I get all data with category ID?
<?php foreach ($result as $rows):
$path = Yii::$app->params['imagePath'];
// print_r ($rows);exit;
?>
<?php $first_name = $rows['first_name'];
//echo $first_name;exit;
$agency_name = $rows['agency_name'];
$seller_name = $rows['seller_name'];
$reff_no = $rows['reff_no'];
$credentials = $rows['credentials'];
$photo = $rows['photo'];
$contact = $rows['contact'];
//echo $contact;exit;
$year_exp = $rows['year_exp'];
$expertise = $rows['expertise'];
$gender = $rows['gender'];
$title = $rows['title'];
$rnf = $rows['reff_no'];
$user_name = $rows['user_name'];
$user_email = $rows['user_email'];
$first_name = $rows['first_name'];
$user_id = $rows['user_id'];
$user_role_id = $rows['user_role_id'];
$service_id1 = $rows['service_id'];
//print_r( $service_id1);
// $service_name = $rows['service_name'];
$credentials = $rows['credentials'];
//echo "User Name: {$user_name}" . "<br>";
//echo "Ratings: {$rating}" . "<br>";
// echo "RNF: {$reff_no}" . "<br>";
//echo "Service Name: {$title}" . "<br>";
//echo "Service id: {$service_id}" . "<br>";
//echo "user role id: {$user_role_id}" . "<br>";
?>
<div class="parent">
<div class="col-lg-12 no-padding">
<div class="col-lg-6">
<div class="big-image">
<?php if($rows['photo']){ ?>
<img src=<?php echo $path; ?><?php echo $rows['photo']; ?> />
<?php } else { ?>
<?php echo Html::img('#web/images/banner/product-main.png'); ?>
<?php } ?>
<?php //echo Html::img('#web/images/banner/product-main.png'); ?></div>
</div>
<div class="col-lg-6">
<div class="product-name">
<h2><?php //echo $first_name?></h2>
<h2><a target="_blank" href="index.php?r=userslisting/user&id=<?php echo $rows['user_id']; ?>"><?php echo $rows['first_name'];?></a> </h2>
</div>
<div class="rating-point">
<p>Reating 4.5/5</p>
</div>
<div class="star">
<span><?php echo Html::img('#web/images/banner/star-full.png'); ?></span>
<span><?php echo Html::img('#web/images/banner/star-full.png'); ?></span>
<span><?php echo Html::img('#web/images/banner/star-full.png'); ?></span>
<span><?php echo Html::img('#web/images/banner/star-hafe.png'); ?></span>
<span><?php echo Html::img('#web/images/banner/star-0.png'); ?></span>
</div>
<div class="rating-point rnf">
<p class="pro-title">RNF</p>
<p class="pro-head-1"><?php echo $rnf?></p>
</div>
<div class="rating-point rank">
<p class="pro-title">Rank/Title</p>
<p class="pro-head-1"><?php echo $title?></p>
</div>
<div class="rating-point ss">
<p class="pro-title">service specialzation</p>
<p class="pro-head-1"><?php echo $expertise?></p>
</div>
<div class="rating-point creden">
<p class="pro-title">Credentials</p>
<p class="pro-head-1"><?php echo $credentials ?></p>
</div>
<div class="rating-point yoe">
<p class="pro-title">Years OF Experience</p>
<p class="pro-head-1"><?php echo $year_exp ?></p>
</div>
<div class="rating-point mail">
<p class="pro-title">Email</p>
<p class="pro-head-1"><?php echo $user_email; ?></p>
</div>
<div class="view-more">
<input type="button" class="btn btn-primary serch-select view-more" value="ENQUIRE" name="ENQUIRE">
<div class="enquiry">
<?php if (Yii::$app->session->hasFlash('contactFormSubmitted')): ?>
<div class="alert alert-success">
Thank you for contacting us. We will respond to you as soon as possible.
</div>
<?php else: ?>
<form id="contact-form" action="" method="post" role="form">
<div class="form-group">
<div class="col-lg-12 no-padding">
<div class="name-1"><input type="text" name="name" class="form-control transparent" value="" placeholder="Name" required> </div>
<div class="contact-1"><input type="text" name="contact" class="form-control transparent" value="" placeholder="Contact No." required> </div>
</div>
</div>
<div class="form-group">
<div class="col-lg-12 no-padding">
<div class="email-1"><input type="email" name="email" class="form-control transparent" value="" placeholder="Email" required> </div>
<div class="subject-1"><input type="text" name="subject" class="form-control transparent" value="" placeholder="Subject" required></div>
</div>
</div>
<div class="form-group"><textarea name="message" class="form-control" rows="6" placeholder="Message"></textarea></div>
<input id="form-token" type="hidden" name="<?=Yii::$app->request->csrfParam?>"
value="<?=Yii::$app->request->csrfToken?>"/>
<div class="form-group submit-button">
<input type="hidden" name="user_id" value="<?php echo $rows['user_id']; ?>" />
<input type="hidden" name="user_name" value="<?php echo $rows['first_name'].' '.$rows['last_name']; ?>" />
<input type="hidden" name="user_email" value="<?php echo $rows['user_email']; ?>" />
<input type="submit" class="btn btn-primary" name="contact-button">
</div>
</form>
<?php endif; ?>
</div>
</div>
</div>
</div>
<div class="clear"></div>
<?php endforeach; ?>
Here is my form
<div class="serch-select-premium">
<?php $form = ActiveForm::begin(['action' =>['site/premiumsearch'], 'id' => '', 'method' => 'get',]); ?>
<?= $form->field($model, 'type_a_keyword')->textInput(['maxlength' => true, 'placeholder' => "Type a keyword"])->label(false); ?>
<?= Html::submitButton('Personal Insurance', ['class' => '','id' => 'personalinsurance', 'name' => 'login-button1']) ?>
<?= Html::submitButton('Corporate Insurance', ['class' => '','id' => 'corporateinsurance', 'name' => 'login-button2']) ?>
<?= Html::submitButton('Solution Based Planning', ['class' => '', 'id' => 'sbasedplanning','name' => 'login-button3']) ?>
<?= Html::submitButton('Tax Planning', ['class' => '','id' => 'taxplanning', 'name' => 'login-button4']) ?>
<?php ActiveForm::end(); ?>
</div>

How to create dynamic field in Yii2?

I have one table where I am saving field name.
Now I want to use those fields in another model. So, How can I give name to that field?
e.g.
I have table named as Config with fields(id,key).
Data can be
1, Blog url
2, Site url
Now, I have 1 form where admin will add those value to database.
In Yii2 we create input field like
<?= $form->field($model, 'name')->textInput() ?>
But I want to create two textboxes with name blog url and site url.
So, How can I create it? What I have to write in place of name?
run this code on your command prompt
php composer.phar require --prefer-dist wbraganca/yii2-dynamicform "*"
after completion of above code.
add the following code in your form.
_form.php
<div class="panel panel-default">
<div class="panel-heading"><h4><i class="glyphicon glyphicon-envelope"></i> Addresses</h4></div>
<div class="panel-body">
<?php DynamicFormWidget::begin([
'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
'widgetBody' => '.container-items', // required: css class selector
'widgetItem' => '.item', // required: css class
'limit' => 4, // the maximum times, an element can be cloned (default 999)
'min' => 1, // 0 or 1 (default 1)
'insertButton' => '.add-item', // css class
'deleteButton' => '.remove-item', // css class
'model' => $modelsAddress[0],
'formId' => 'dynamic-form',
'formFields' => [
'name',
],
]); ?>
<div class="container-items"><!-- widgetContainer -->
<?php foreach ($modelsAddress as $i => $modelAddress): ?>
<div class="item panel panel-default"><!-- widgetBody -->
<div class="panel-heading">
<h3 class="panel-title pull-left">Address</h3>
<div class="pull-right">
<button type="button" class="add-item btn btn-success btn-xs"><i class="glyphicon glyphicon-plus"></i></button>
<button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button>
</div>
<div class="clearfix"></div>
</div>
<div class="panel-body">
<?php
// necessary for update action.
if (! $modelAddress->isNewRecord) {
echo Html::activeHiddenInput($modelAddress, "[{$i}]id");
}
?>
<?= $form->field($model, "[{$i}]name")->textInput(['maxlength' => true]) ?>
</div>
</div>
<?php endforeach; ?>
</div>
<?php DynamicFormWidget::end(); ?>
</div>
</div>

Yii CJuiDialog isn't being recognized

I've went through this tutorial http://www.yiiframework.com/wiki/561/ajax-login-form-with-validation-errors-inside-jquery-modal-dialog/ It appears to be functioning properly, but instead of the form being in the modal dialog, it just renders it right on the page like zii.widgets.jui.CJuiDialog isn't even there.
<?php $this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'login-dialog',
'options'=>array(
'title'=>'Login',
'autoOpen'=>false,
),
));?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'user_login_form',
'enableAjaxValidation'=>false,
'enableClientValidation'=>true,
'method' => 'POST',
'clientOptions'=>array(
'validateOnSubmit'=>true,
'validateOnChange'=>true,
'validateOnType'=>false,
),
)); ?>
<h1>
Login</h1>
<p>
Please fill out the following form with your login credentials:</p>
<p class="note">
Fields with <span class="required">*</span> are required.</p>
<div id="login-error-div" class="errorMessage" style="display: none;">
</div>
<div class="row">
<?php echo $form->labelEx($model,'username'); ?>
<?php echo $form->textField($model,'username',array("onfocus"=>"$('#login-error- div').hide();")); ?>
<?php //echo $form->error($model,'username'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'password'); ?>
<?php echo $form->passwordField($model,'password',array("onfocus"=>"$('#login-error- div').hide();")); ?>
<?php //echo $form->error($model,'password'); ?>
<p class="hint">
Hint: You may login with <tt>demo/demo</tt>.
</p>
</div>
<div class="row rememberMe">
<?php echo $form->checkBox($model,'rememberMe'); ?>
<?php echo $form->label($model,'rememberMe'); ?>
<?php echo $form->error($model,'rememberMe'); ?>
</div>
<div class="row submit">
<?php echo CHtml::ajaxSubmitButton(
'Sign In',
array('/site/login.GetLogin'),
array(
'beforeSend' => 'function(){
$("#login").attr("disabled",true);
}',
'complete' => 'function(){
$("#user_login_form").each(function(){ this.reset();});
$("#login").attr("disabled",false);
}',
'success'=>'function(data){
var obj = jQuery.parseJSON(data);
// View login errors!
// alert(data);
if(obj.login == "success"){
$("#user_login_form").html("<h4>
Login Successful! Please Wait...</h4>
");
parent.location.href = "/";
}
else{
$("#login-error-div").show();
$("#login-error-div").html("Login failed! Try again.");$("#login-error-div").append("
");
}
}'
),
array("id"=>"login","class" => "btn btn-primary")
); ?>
</div>
<?php $this->endWidget(); ?>
</div>
<!-- form -->
<?php $this->endWidget('zii.widgets.jui.CJuiDialog'); ?>
Its suppose to render like this above so when i click the link below it opens
echo CHtml::link('Login', array('/site/login.GetLogin'), array('onclick'=>'$("#login-dialog").dialog("open"); return false;'));
Its built in a widget, if you have a look at the tutorial. Here's the complete widget
<?php
class loginProvider extends CWidget{
public static function actions(){
return array(
'GetLogin'=>'application.components.actions.getLogin',
);
}
public function run(){
$this->renderContent();
}
protected function renderContent(){
echo '<span style="float:right;">';
if(Yii::app()->user->isGuest){
echo CHtml::link('Login', array('/site/login.GetLogin'), array('onclick'=>'$("#login-dialog").dialog("open"); return false;'));
echo '</span>';
$this->getController()- >renderPartial('application.components.views.login',array('model'=>new LoginForm));
}
else
echo CHtml::link('Logout ('.Yii::app()->user->name.')', array('site/logout'), array('visible'=>!Yii::app()->user->isGuest));
echo '</span>';
}
}

How to seperate radiobuttons from radiobuttonlist and set it default

I'm new to Yii framework. I'm using two radiobuttonlist in my advanced search form. I'm using the below lines to create radiobuttonlist.
<div class="row">
<?php #echo $form->label($model,'ReviewedDate'); ?>
<?php echo $form->radioButtonList($model, 'ReviewedDate',
array('1' => 'Reviewed', '' => 'Not Reviewed')
); ?>
</div>
<div class="row">
<?php echo $form->radioButtonList($model, 'Approved',
array('0' => 'Rejected', '1' => 'Approved')
); ?>
</div>
Now, I want to create a seperate radiobutton(4 buttons - Approved, Rejected, Reviewed, Not Reviewed) from the radiobuttonlist and Not reviewed has to be the selected by default when I go to that page.At a time only one button can be selected. How can I do this
Try:
<div class="row">
<?php #echo $form->label($model,'ReviewedDate'); ?>
<?php echo $form->radioButtonList($model, 'ReviewedDate',
array('1' => 'Reviewed', '' => 'Not Reviewed','2'=>'Approved','3'=>'Reviewed','4'=>'rejected'
); ?>
</div>
<script> $( document ).ready(function() {
$('your id /selector radio button').prop('checked',true);
}); </script>

Yii - Pass filtered CGridView data to a PDF format

I have a web application that uses CGridView to display filtered data from the $model based on user-entered search parameters.
My goal is for the user to be able to hit a button to export the filtered data to a PDF.
In order to accomplish this I'm using the extension yii-pdf.
Do I need to pass the information stored in the CActiveDataProvider array to be used in a separate controller and view for the PDF creation?
It seems easier to use the same controller/action and render the data into a view that can then be exported to PDF. But, alas, I cannot figure out how to do this.
Thanks in advance.
_search View:
<div class="wide form">
<?php
$form = $this->beginWidget('GxActiveForm', array(
'action' => Yii::app()->createUrl($this->route),
'method' => 'get',
));
?>
<!-- Search Fields here -->
<!-- Search and Export to PDF buttons -->
<div class="row buttons">
<?php echo GxHtml::submitButton(Yii::t('app', 'Search')); ?>
<?php echo GxHtml::button(Yii::t('app', 'PDF'), array('id' => 'exportToPdf')); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- search-form -->
_pdf View
<div class="pdfContainer" id="pdfPage">
<div class="pdfHeader">
<img src="images/logo.png" style="float:left; text-align: top;"></img>
<div class="pdfTitle" style="text-align: right; float: right;">
<h3>Service Report</h3>
</div>
</div><!-- header -->
<?php echo "Prepared by: ".Yii::app()->user->name."\n" ?>
<?php **//Possibly echo contents here?** ?>
<div class="clear"></div>
<div class="pdfFooter">
</div><!-- footer -->
</div><!-- page -->
</div>
controller/action
public function actionPdf(){
$this->layout='pdf';
/* mPDF */
$mPDF1 = Yii::app()->ePdf->mpdf();
/* render (full page) */
$mPDF1->WriteHTML($this->render('pdf', array(), true));
/* renderPartial (only 'view' of current controller) */
$mPDF1->WriteHTML($this->renderPartial('pdf', array(), true));
/* Outputs ready PDF */
$mPDF1->Output();
}
admin View:
<?php
Yii::app()->clientScript->registerScript('search', "
$('#exportToPdf').click(function(){
window.location = '". $this->createUrl('Weeklyservicereport/pdf') . "?' + $(this).parents('form').serialize() + '&export=true';
return false;
});
$('.search-form form').submit(function(){
$('#weeklyservicereport-grid').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
");
?>
<div class="search-form" style="display:block">
<?php $this->renderPartial('_search', array('model' => $model,)); ?>
</div> <!-- Search Form -->
/* Gridview Widget */
<?php $this->widget('application.components.widgets.tlbExcelView', array(
'id' => 'weeklyservicereport-grid',
'dataProvider' => $model->search(),
.....
.....
'columns'=>array(
/* Column names */
),
));
?>
You're pretty close of the solution, I will write here the logic that you can use.
Create a view for your PDF header;
Create a view for your PDF footer;
Create a view for your Gridview;
view: _pdf_header.php
<div class="pdfHeader">
<img src="images/logo.png" style="float:left; text-align: top;"></img>
<div class="pdfTitle" style="text-align: right; float: right;">
<h3>Service Report</h3>
</div>
</div>
view: _pdf_footer.php
<div class="pdfFooter">
<h5>Your Footer Page</h5>
</div>
view: _gridview.php
<?php $this->widget('application.components.widgets.tlbExcelView', array(
'id' => 'weeklyservicereport-grid',
'dataProvider' => $dataProvider,
'columns' => array( /*YOUR COLUMNS */ ),
));
?>
In your actionPdf, you just render partial the views, as suggested by #ineersa:
public function actionPdf(){
$this->layout = 'pdf';
$model = new Model();
$model->attributes = $_GET['Model']; /* to execute the filters (if is the case) */
$dataProvider = $model->search();
/* if yu want to ignore the pagination and retrieve all records */
$dataProvider->pagination = false;
$mPDF1 = Yii::app()->ePdf->mpdf();
$mPDF1->WriteHTML($this->renderPartial('_pdf_header', array(), true));
$mPDF1->WriteHTML($this->renderPartial('_gridview', array('dataProvider' => $dataProvider), true));
$mPDF1->WriteHTML($this->renderPartial('_pdf_footer', array(), true));
$mPDF1->Output();
}
Reference:
http://www.yiiframework.com/forum/index.php/topic/15677-printing-a-cgridview/