• About Sarwar
  • Portfolio
  • আমার বাংলা

sarwar's weblogs

~ story of web applications…..

sarwar's weblogs

Tag Archives: paginator

cakephp ajax pagination using jquery

26 Tuesday Apr 2011

Posted by Sarwar in CakePHP, Framework, JavaScript, jquery, PHP

≈ 9 Comments

Tags

ajax, ajax pagination cakephp, jquery, paginator


I tried to use cakephp default ajax pagination, it seems not working with me. I tried with different way.

The following code using for pagination.

<div class="paginator">
        <?php echo $paginator->first(' First ', null, null, array('class' => 'disabled')); ?>
        <?php echo $paginator->prev('Previous ', null, null, array('class' => 'disabled')); ?>
        <?php echo $paginator->numbers(); ?>
       <?php echo $paginator->next(' Next ', null, null, array('class' => 'disabled')); ?>
        <?php echo $paginator->last(' Last ', null, null, array('class' => 'disabled')); ?>
</div>   

Now below that code I used the following java script code

<script>
    $(document).ready(function(){
        $(".paginator a").click(function(){
            $("#updated_div_id").load(this.href);
            return false;
        })
    });
</script>

Here, I just fire an event on click under paginator div, once you click on a link under that div, it fetch the url (this.herf) and calling page using ajax, You must prepared the controller for ajax based.

for example your controller calling ‘ajax_pages’ action.

function ajax_pages(){
        $this->layout = 'ajax';
        $this->paginate = array(
                                'order' => array('Module.created_date' => 'desc'), 
                                'recursive' => -1,
                                "limit" => PAGINATION_LIMIT
                                );
        
        $conditions['Module.module_type'] = $module_type;
        $data = $this->paginate("Module", $conditions);
        $this->set(compact("data"));  
}

Its work for me 🙂

Advertisement

Share this:

  • Tweet
  • Email

Like this:

Like Loading...

passing get variable in cakephp pagination url

12 Tuesday Jan 2010

Posted by Sarwar in CakePHP, Framework, PHP

≈ 17 Comments

Tags

argument, CakePHP, GET, pagination, paginator, parameter passed, PHP


For searching we many need to pass variable like ?keyword=test, and we may need to add pagination withen the search, Here I describe multiple cases where we may need to use pagination and how we manage the url for pagination when we make some searching

Case 1: if the url like the following
http://www.mydomain.com/controller/method/?keyword=test1&opt=test2

In this case we need to add the paginator option like this
First we retrive the passing variable and assign value, we can get it from “$this->params[‘url’]

$urls = $this->params['url']; $getv = "";
foreach($urls as $key=>$value)
{
if($key == 'url') continue; // we need to ignor the url field
$getv .= urlencode($key)."=".urlencode($value)."&"; // making the passing parameters
}
$getv = substr_replace($getv ,"",-1); // remove the last char '&'

Now we have the all get parameter, lest assign this to paginator option

$paginator->options(array('url' => array("?"=>$getv)));

Now all the pagination links always taking this get parameter so now if we gos to the next page the url look like this
http://www.mydomain.com/controller/method/page:2?keyword=test1&opt=test2

Now If we need passing an argument as id like the following
http://www.mydomain.com/controller/method/1/?keyword=test1&opt=test2
where 1 is an id or something we get this 1 from $this->passedArgs[0] So now we have to set the paginator option like this

$paginator->options(array('url' => array($this->passedArgs[0],"?"=>$getv)));

If we have passed more than one argument, we need to take it

$pass_argument = $this->passedArgs[0]."/"$this->passedArgs[1]."/".$this->passedArgs[2]."/";
$paginator->options(array('url' => array($pass_argument,"?"=>$getv)));

It depend on you how much you want to passed the argument, if you faced any problem print the $this->passedArgs and see how it organize the argument. Its really easy and I’ve already used it. Cheers

–new update
I got the idea from comments, here is update, the following code will useful for multiple arguments or params.

//extract the get variables
$url = $this->params['url'];
unset($url['url']);
$get_var = http_build_query($url);

$arg1 = array(); $arg2 = array();
//take the named url
if(!empty($this->params['named']))
$arg1 = $this->params['named'];

//take the pass arguments
if(!empty($this->params['pass']))
$arg2 = $this->params['pass'];

//merge named and pass
$args = array_merge($arg1,$arg2);

//add get variables
$args["?"] = $get_var;

$paginator->options(array('url' => $args));

done.. But I’m trying to make better solution, will update it soon.

Share this:

  • Tweet
  • Email

Like this:

Like Loading...

Author

  • Sarwar

Categories

  • .htaccess
  • Apache
  • API
  • CSS
  • Debug
  • Framework
    • CakePHP
  • HTML
  • JavaScript
    • Ajax
    • ckeditor
    • jquery
    • jQuery UI
    • tinymce
  • Joomla
    • Virtumart
  • Linux
  • MySQL
  • PHP
  • SVN
  • Twitter
  • WHM/cPanel
View Sarwar Hossain's profile on LinkedIn
Follow bdsarwar on Twitter

Tweets

  • RT @ESPNUK: If Erling Haaland wanted to match Cristiano Ronaldo's 700 league goals, he'd have to score 40 goals a season until the year 203…    1 month ago
  • RT @Cristiano: Great team effort and a good victory. We stand together. Let’s go, United! 💪🏽 https://t.co/GnjAR3oM3s    3 months ago
  • RT @Cristiano: Hard work always pays off 🙏🏽💪🏽 https://t.co/kMqIpB2nfV    5 months ago
  • RT @realDonaldTrump: Just finished a very good conversation with President Xi of China. Discussed in great detail the CoronaVirus that is r…    2 years ago
  • “Running a small business without a plan is a lot like driving without directions.” — @GoldmanSachs via @appexchange    6 years ago
  • RT @TechCrunch: 5K people turn up to catch Pokémon in Chicago tcrn.ch/2aaLRys https://t.co/VVQSd7nmN4    6 years ago

Flickr Photos

From Helipad ViewAbove the CloudHillNear to SkySunset Moment#sunset #beach #ocean #coxsbazar#jamroll #food #deliciousfood #homemade  #homemadefood#seaside #ocean #oceanview #travelphotography #coxsbazar #bayofbengal #travel #longestbeach#beach #lifeguard #seaside #holiday #tour #longestbeach #travel #travelphotography #coxsbazar #bayofbengal#resort #mountains
More Photos

Archives

  • February 2012 (1)
  • January 2012 (2)
  • August 2011 (1)
  • July 2011 (1)
  • June 2011 (2)
  • May 2011 (2)
  • April 2011 (1)
  • March 2011 (3)
  • December 2010 (3)
  • November 2010 (1)
  • October 2010 (4)
  • September 2010 (1)
  • June 2010 (1)
  • May 2010 (2)
  • April 2010 (1)
  • March 2010 (1)
  • January 2010 (2)
  • July 2009 (1)
  • January 2009 (1)
  • August 2008 (1)

Recent Comments

  • Kush on how to cakephp in a sub-directory, access it from root using .htaccess
  • Mr Griever on Access session data in a model -cakephp
  • apnarahimyarkhan on cakephp- CONCAT in query, Virtual Fields and make a drop down
  • Toko Kunci Pintu Murah on set & reset form text value onfocus, onblur, onclick using javascript
  • nevitaputri1.doodlekit on cakephp- CONCAT in query, Virtual Fields and make a drop down
  • RSS - Posts
  • RSS - Comments

Meta

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.com

Create a free website or blog at WordPress.com.

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Follow Following
    • sarwar's weblogs
    • Join 328 other followers
    • Already have a WordPress.com account? Log in now.
    • sarwar's weblogs
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
%d bloggers like this: