Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How to apply Cake php ajax pagination?

Answer Posted / facebittu

class ReviewsController extends AppController {

var $name = 'Reviews';
var $uses = array('Review','Country','School','User');
var $components = array('RequestHandler');
var $helpers =
array('Html','Form','Javascript','Ajax','Fck');
var $paginate_limit_front = '10';
var $paginate = "";

function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('*');
}



##########################functions for paging in review
results####################################


function searchresults($page_no = ''){
$this->layout='default1';
$this->set("page_no", $page_no);
}// ef


function search_ajax( $search_srting='') {

$this->set_paginate_limit_search($search_srting); //
Setting Paginate Limit

$this->layout=null;
Configure::write('debug', 0);

$data = $this->paginate();
$countRecords=count($data);
$this->set("serchResultsReviews", $data);

$this->set("paginate_limit", $this->paginate_limit_front);

// Finding Page No (for Sr. No.)
$page_no_arr = explode(":", $_REQUEST['url']);

$this->set("page_no", $page_no_arr[1]);


$this->set("search_srting", $search_srting);
$this->set("total_records", $countRecords);

}

function set_paginate_limit_search( $search_srting = '' )
{

if( $search_srting == '' ){
$this->paginate
=array('conditions'=>array('Review.status'=>1),
'order'=>array('Review.id desc'), 'limit' =>
$this->paginate_limit_front);
}
else
{
$this->paginate =array('conditions' =>array('or'=> array(

'Review.title LIKE' => '%'.$search_srting.'%',
'Review.rating LIKE' => '%'.$search_srting.'%',
'Review.description LIKE' =>
'%'.$search_srting.'%',
'School.name LIKE' => '%'.$search_srting.'%'
)
),
'fields' =>
array('Review.id','Review.title','Review.type','Review.rating','Review.description','School.id','School.name','School.image_url','User.firstname','User.email'),
'limit' => $this->paginate_limit_front
);

} // else ends here

} // ef
###############################################################


}


###################action page################

<script type="text/javascript">

function loadPiece(href,divName) {
// Loading Image....
//$('#imageList').fadeOut('slow');
document.getElementById('imageList').innerHTML =
'<br/><img src="<?php e($html->url('/img/ajax-loader.gif'));
?>" />';//+document.getElementById('imageList').innerHTML;

$(divName).load(href, {}, function(a,b){
//alert(a);
var divPaginationLinks = divName+" #pagination a";
$(divPaginationLinks).click(function() {
var thisHref = $(this).attr("href");
loadPiece(thisHref,divName);
$('#imageList').fadeIn('slow');
return false;
});
});
}

$(document).ready(function() {
<?php $searchText = $this->data['Review']['search']; ?>
loadPiece("<?php echo
$html->url(array('controller'=>'reviews','action'=>'search_ajax/'.$searchText));?>","#imageList");
});

</script>
<div id="imageList" style="text-align:center;">
</div>


#########################ajax ctp################3


<div class="content">
<div id="blueBox">
<div class="top">
<span class="left"><?php echo
$html->image('blue-border-box-top-left.gif',array('alt'=>''));?></span>
<span class="right"><?php echo
$html->image('blue-border-box-top-right.gif',array('alt'=>''));?></span>
<div class="clear"></div>
</div>

<?php
$total=count($serchResultsReviews);
if($total){ ?>
<h3><?php echo $total; ?> displayed from Total <?php echo
$total_records; ?> </h3>
<?php for($i=0;$i<$total;$i++){

if($serchResultsReviews[$i]['School']['image_url']==""){$serchResultsReviews[$i]['School']['image_url']="noImage.jpg";}

?>

<div class="content">
<div style="width:700px; margin:auto">
<div class="userProfileimage">
<?php echo
$html->image('files/users/'.$serchResultsReviews[$i]['School']['image_url'].'',array('alt'=>'','height'=>'150','width'=>'150'));?>
</div>
<div class="userDetails"><strong>Title :</strong><a
href="textreview/<?php echo
$serchResultsReviews[$i]['Review']['id'] ;?>"><?php echo
$serchResultsReviews[$i]['Review']['title'] ; ?></a></div>
<div class="userDetails"><strong>Rating :</strong><?php
echo
$html->image('star-'.$serchResultsReviews[$i]['Review']['rating'].'.gif',array('alt'=>''));?></div>
<div class="userDetails"><strong>Description
:</strong><?php echo
$showIntro=substr($serchResultsReviews[$i]['Review']['description'],0,50);
?>...</div>
<div class="userDetails"><strong>School name :</strong><a
href="<?php
e($html->url('/schools/detail/'.$serchResultsReviews[$i]['School']['id'].''));
?>"><?php echo $serchResultsReviews[$i]['School']['name'] ;
?></a></div>
</div>
</div>
<div class="clear"></div>
<?php }
}
else {
echo "<h3>Sorry no users Profiles found</h3>";
}
?>



<div class="bottom">
<span class="left"><?php echo
$html->image('blue-border-box-bottom-left.gif',array('alt'=>''));?></span>
<span class="right"><?php echo
$html->image('blue-border-box-bottom-right.gif',array('alt'=>''));?></span>
<div class="clear"></div>
</div>
</div>
</div>
<div id="pagination">
<div >
<?php
echo $paginator->first("<<",
array('class'=>'footer_nav','url'=>$search_srting));
echo '&nbsp;&nbsp;';
//echo $paginator->prev("<",
array('class'=>'footer_nav'));
echo '&nbsp;&nbsp;';
echo $paginator->numbers(array('separator'=>' |
','url'=>$search_srting));
echo '&nbsp;&nbsp;';
//echo $paginator->next(">",
array('class'=>'footer_nav'));
echo '&nbsp;&nbsp;';
echo $paginator->last(">>",
array('class'=>'footer_nav','url'=>$search_srting));

?>
</div>

</div>

Is This Answer Correct ?    9 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the different types of array in php?

919


What is factory pattern in php?

872


Does browser understand php?

869


Can you extend a final defined class?

8925


What is the difference between include and require?

939


What is an anti csrf token?

872


Explain mysql_errno()?

957


What is traits? How it is used in php?

1006


How to execute an sql query?

924


Where are the persistent cookies stored on your computer?

940


What is the purpose of basename() function in PHP?

991


Which is the correct way to check if a session has already been started ?

931


What is the difference between apache and tomcat?

959


How can I make a script that can be bilingual (supports english, german)?

972


Which php framework is best for beginners?

1031