Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8012629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:22:55+00:00 2026-06-04T19:22:55+00:00

I’m using CakePHP to create a frontend UI for PowerDNS, using a MySQL backend.

  • 0

I’m using CakePHP to create a frontend UI for PowerDNS, using a MySQL backend. On the front page of the app I want to have a handful of widgets (‘Quickly add a record’, ‘Quickly add a domain’ etc.). One of the widgets I want is a paginated list of existing domains.

The index function in DomainsController.php looks like this:

public $paginate = array(
  'fields'     => array('id', 'name'),
  'limit'      => 25,
  'order'      => array( 'name' => 'asc' ),
  'conditions' => array( "NOT" => array( "name LIKE" => "%.arpa" ) )
);

public function index() {
  $domains = $this->paginate();
  if ( $this->request->is('requested')) {
    return $domains;
  } else {
    $this->set('domains', $domains);
  }
}

I’ve created an element that looks like this:

<?php $domains = $this->requestAction('Domains/index'); ?>

<ol>
  <?php foreach( $domains as $domain) :?>
    <li>echo $domains['domain']['name']</li>
  <?php endforeach; ?>
</ol>

<?php echo $paginator->numbers(); ?>

When I visit the front page, I get an ‘Undefinied variable: paginator’ error. I’ve tried using $this->Paginator->numbers() instead but that just gives me ‘Undefined property: View::$Paginator’. Adding the ‘Paginator’ helper to PagesController.php doesn’t help either – $this->Paginator becomes available but I get ‘Undefined index: pageCount’.

Is it possible to do this kind of pagination from an element on home.ctp or am I going to have to do some custom JavaScript stuff?

EDIT

Now I’m getting somewhere: I changed my DomainsController index function to this:

public function index() {
 $domains = $this->paginate();
 $paginator = $this->params;
 if ( $this->request->is('requested')) {
  return compact( 'domains', 'paginator' );
 } else {
  $this->set('domains', $domains);
 }
}

And added the following to the domainList.ctp element:

<?php 
$result = $this->requestAction('Domains/index');
$domains = $result['domains'];
$this->Paginator->request = $result['paginator'];
?>

<ol>
  <?php foreach( $domains as $domain) :?>
    <li>echo $domains['domain']['name']</li>
  <?php endforeach; ?>
</ol>

<?php echo $paginator->numbers(); ?>

$this->Paginator is now working properly and I can access all of its methods and properties and so on as normal. My problem now is that if I click on, say, ‘2’, the browser navigates to /pages/home/page:2 but the domain list still shows page 1. Just need to figure out how to pass ‘page:2’ to the element. And AJAX-ify the whole thing so that I don’t need to refresh the whole page.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:22:57+00:00Added an answer on June 4, 2026 at 7:22 pm

    OK, I solved this problem, although my solution probably isn’t very elegant.

    DomainsController.php has a listDomains() function that looks like this:

    public function listDomains() {
     $domains = $this->paginate(); 
     $paginator = $this->params;
     if ( $this->request->is('ajax') ) {
      $this->set( 'domains', $domains );
     }
     if ( $this->request->is('requested')) {
      return array( 'domains' => $domains, 'paginator' => $paginator, 'paging' => $this->params['paging'] );
     } else {
      $this->set( 'domains', $domains );
     }
    }
    

    home.ctp references an element called domainList.ctp. domainList.ctp, below, in turn uses requestAction() – I know, I know – to call the domainList() function above. Bequest the request is requested, an array containing the values of $domains and $paginator is sent back to the element.

    domainList.ctp contains this code:

    <?php
    $result = $this->requestAction('Domains/listDomains', array('updateId' => 'domainList') );
    $domains = $result['domains'];
    $paginator = $result['paginator'];
    $this->Paginator->request = $paginator;
    
    $this->Paginator->options(array(
     'update' => '#domainList',
     'evalScripts' => true,
     'url' => array('controller' => 'Domains', 'action' => 'listDomains', 'updateId' => 'domainList' ),
    ));
    
    ?>
    

    Essentially what I’m doing here is manually re-populating $this->Paginator->request with the params that were originally sent to the DomainController’s domainList() function. This lets me access the various paginator functions, like numbers(), prev() and next(), properly. It’s a bit messy but guess what? It gets a little messier.

    When you click on the links created by those paginator functions, the ‘if ( $this->request->is(‘ajax’) )’ segment is executed and the div object on the page is updated with the contents of View/Domains/domainList.ctp instead of View/Elements/domainList.ctp. The contents of View/Domains/domainList.ctp is more or less the same as the corresponding element and the two have to be kep more or less syncronised. The difference is that we don’t need to manually populate $this->Paginator:

    <?php
    $this->Paginator->options(array(
     'update' => '#domainList',
     'evalScripts' => true,
     'url' => array('controller' => 'Domains', 'action' => 'listDomains', 'updateId' => 'domainList' ),
    ));
    
    ?>
    

    Like I said, it’s messy and inelegant but it worked for me. I’d be happy to know if anyone has a less kludgy way to do this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.