Sunday, August 28, 2011

Pagination and JQuery: Passing parameters with JQuery to controller

Hi,

this is hard to explain quick but i'll try :)

I have one view "profile" in my controller. in that profile.ctp i have
two elements. "following" and "created". in each element i want
paging.

i got it work for the element "following" but i need also for
"created". The Catch:

i need to use one paginate in my profile function for two elements. so
my approach is, depending on what paginator you click, "following" or
"created", a specific variable is passed to the controllers

$this->RequestHandler->isAjax()

function, which is rendering the specific element (following or
created). And thats what i got so far:


controller:
===============================

public $paginate = array(
'Link' =>
some code
)),

'Created' =>
some code
)
);


function profile()
{


$following = $this->paginate('Link', $conditions);
$created = $this->paginate('Created');

$this->set('following', $following);
$this->set('created', $created);


if ($this->RequestHandler->isAjax()) {
$this->render('/elements/users/following');
return;
}

}


view "profile"
============================

$('#pagination_follow a').live('click', function() {
var url = $(this).attr("href");
$('#following_popup').load(url);
return false;
});

$('#pagination_created a').live('click', function() {
var url = $(this).attr("href");
$('#following_popup').load(url);
return false;
});

so basically i would code two divs "pagination_created" in element
"created" and
"pagination_follow" in the element "following". depending on what div
a user clicks i want to pass a value to the isAjax() function in
controller, like this


if ($this->RequestHandler->isAjax())
{

when user clicks on div "pagination_follow"
$this->render('/elements/users/following');
return;

when user clicks on div "pagination_created"
$this->render('/elements/users/created');
return;
}

so pagination knows what element to render....is that possible and how
can i pass a variable to the controller?

thanks a lot :)

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: