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 6250563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:26:55+00:00 2026-05-24T13:26:55+00:00

i spent the last 2 days looking for a solution for a problem with

  • 0

i spent the last 2 days looking for a solution for a problem with pagination in cakephp.

In short, i need diferent pagination methods for the same model. The index action will use the default method and the view action will use the method with a custom query.

Based on the OOP’s inheritance concept, i thought that the solution was to extend my model and override the pagination method on the extended model. So, i can call from the controller the default pagination method for the index action and the custom methods for the view action.

The question is: how can i extend my model class? Will work this ideia?

this is my model:

<?php
class Communication extends AppModel {

var $name = 'Communication';
var $displayField = 'title';

//The Associations below have been created with all possible keys, those that are not needed can be removed

var $hasMany = array(
    'Interaction' => array(
        'className' => 'Interaction',
        'foreignKey' => 'communication_id',
        'dependent' => false,
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'exclusive' => '',
        'finderQuery' => '',
        'counterQuery' => ''
    ),
    'Star' => array(
        'className' => 'Star',
        'foreignKey' => 'communication_id',
        'dependent' => false,
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'exclusive' => '',
        'finderQuery' => '',
        'counterQuery' => ''
    )
);

var $hasAndBelongsToMany = array(
    'Document' => array(
        'className' => 'Document',
        'joinTable' => 'communications_documents',
        'foreignKey' => 'communication_id',
        'associationForeignKey' => 'document_id',
        'unique' => true,
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'finderQuery' => '',
        'deleteQuery' => '',
        'insertQuery' => ''
    ),
    'Event' => array(
        'className' => 'Event',
        'joinTable' => 'communications_events',
        'foreignKey' => 'communication_id',
        'associationForeignKey' => 'event_id',
        'unique' => true,
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'finderQuery' => '',
        'deleteQuery' => '',
        'insertQuery' => ''
    ),
    'Meeting' => array(
        'className' => 'Meeting',
        'joinTable' => 'communications_meetings',
        'foreignKey' => 'communication_id',
        'associationForeignKey' => 'meeting_id',
        'unique' => true,
        'conditions' => '',
        'fields' => '',
        'order' => 'date_create DESC',
        'limit' => '',
        'offset' => '',
        'finderQuery' => '',
        'deleteQuery' => '',
        'insertQuery' => ''
    ),
    'User' => array(
        'className' => 'User',
        'joinTable' => 'communications_users',
        'foreignKey' => 'communication_id',
        'associationForeignKey' => 'user_id',
        'unique' => true,
        'conditions' => '',
        'fields' => '',
        'order' => 'name',
        'limit' => '',
        'offset' => '',
        'finderQuery' => '',
        'deleteQuery' => '',
        'insertQuery' => ''
    )
);

function getComInfos($id) {

    $this->unbindModel(array('hasAndBelongsToMany'=>array('Document','Event','Meeting')));
    $this->unbindModel(array('hasMany'=>array('Star','Interaction')));
    $communication_infos = $this->read(null, $id);

    //debug($communication_infos);

    return $communication_infos;

}

function getComLinks($id) {

    $communication_links = $this->query("
    SELECT 'documents' AS 'type', 'D' AS 'marker', d.id AS id, d.date_create AS date, du.user_id AS info_aux, d.title AS title, d.desc AS content 
    FROM communications_documents AS cd
    JOIN documents AS d ON d.id = cd.document_id
    JOIN documents_users AS du ON du.document_id = d.id
    WHERE cd.communication_id = ".$id."

    UNION

    SELECT 'events' AS 'type', 'E' AS 'marker', e.id AS id, e.date_create AS date, e.institution AS info_aux, e.title AS title, e.desc AS content
    FROM communications_events AS ce
    JOIN events AS e ON e.id = ce.event_id
    WHERE ce.communication_id =".$id."

    UNION

    SELECT 'meetings' AS 'type', 'R' AS 'marker', m.id AS id, m.date_create AS date, m.site AS info_aux, m.title AS title, m.desc AS content
    FROM communications_meetings AS cm
    JOIN meetings AS m ON m.id = cm.meeting_id
    WHERE cm.communication_id =".$id."

    UNION

    SELECT 'interactions' AS 'type', 'C' AS 'marker', i.id AS id, i.date_create AS date, i.user_id AS info_aux, i.title AS title, i.content AS content
    FROM interactions AS i
    WHERE i.communication_id =".$id."

    ORDER BY date DESC
    ");

    //debug($communication_links);

    return $communication_links;

}

}

And this is my two custom pagination method, that i need to use just to the view action:

function paginate($conditions, $fields, $order, $limit, $page = 1, $recursive = null, $extra = array()) {

    $recursive = -1;
    return $this->query("
    SELECT 'documents' AS 'type', 'D' AS 'marker', d.id AS id, d.date_create AS date, du.user_id AS info_aux, d.title AS title, d.desc AS content 
    FROM communications_documents AS cd
    JOIN documents AS d ON d.id = cd.document_id
    JOIN documents_users AS du ON du.document_id = d.id
    WHERE cd.communication_id = 137

    UNION

    SELECT 'events' AS 'type', 'E' AS 'marker', e.id AS id, e.date_create AS date, e.institution AS info_aux, e.title AS title, e.desc AS content
    FROM communications_events AS ce
    JOIN events AS e ON e.id = ce.event_id
    WHERE ce.communication_id =137

    UNION

    SELECT 'meetings' AS 'type', 'R' AS 'marker', m.id AS id, m.date_create AS date, m.site AS info_aux, m.title AS title, m.desc AS content
    FROM communications_meetings AS cm
    JOIN meetings AS m ON m.id = cm.meeting_id
    WHERE cm.communication_id = 137

    UNION

    SELECT 'interactions' AS 'type', 'C' AS 'marker', i.id AS id, i.date_create AS date, i.user_id AS info_aux, i.title AS title, i.content AS content
    FROM interactions AS i
    WHERE i.communication_id = 137

    ORDER BY date DESC
    LIMIT ".(($page-1)*$limit).", ".$limit);

}

function paginateCount($conditions = null, $recursive = 0, $extra = array()) {
    $sql = "
    SELECT 'documents' AS 'type', 'D' AS 'marker', d.id AS id, d.date_create AS date, du.user_id AS info_aux, d.title AS title, d.desc AS content 
    FROM communications_documents AS cd
    JOIN documents AS d ON d.id = cd.document_id
    JOIN documents_users AS du ON du.document_id = d.id
    WHERE cd.communication_id = 137

    UNION

    SELECT 'events' AS 'type', 'E' AS 'marker', e.id AS id, e.date_create AS date, e.institution AS info_aux, e.title AS title, e.desc AS content
    FROM communications_events AS ce
    JOIN events AS e ON e.id = ce.event_id
    WHERE ce.communication_id = 137

    UNION

    SELECT 'meetings' AS 'type', 'R' AS 'marker', m.id AS id, m.date_create AS date, m.site AS info_aux, m.title AS title, m.desc AS content
    FROM communications_meetings AS cm
    JOIN meetings AS m ON m.id = cm.meeting_id
    WHERE cm.communication_id = 137

    UNION

    SELECT 'interactions' AS 'type', 'C' AS 'marker', i.id AS id, i.date_create AS date, i.user_id AS info_aux, i.title AS title, i.content AS content
    FROM interactions AS i
    WHERE i.communication_id = 137

    ORDER BY date DESC
    ";
    $this->recursive = $recursive;
    $results = $this->query($sql);
    return count($results);
}`
  • 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-05-24T13:26:55+00:00Added an answer on May 24, 2026 at 1:26 pm

    In the controller, I would set some very general options for each model, like so:

        class SampleController extends AppController {
            ...
            var $paginate = array(
                'ModelName' => array( ...general options... )
            );
            ...
        }
    

    And then inside each action, you can customize it:

        ...
        function index(){
            $this->paginate = array(
                ... specific pagination options for index action ...
            );
            $this->paginate('ModelName');
        }
        ...
        function view(){
            $this->paginate = array(
                ... specific pagination options for view action ...
            );
            $this->paginate('ModelName');
        }
    

    This way you can have custom pagination results for each action.

    Hope that helps.

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

Sidebar

Related Questions

I've spent the last two days trying to find a solution to this problem
Ok so Ive spent the last two days looking for a good simple example
Having spent the last couple of days experimenting with C++ operator[] methods, I've come
I've spent the last few days scouring the site looking for an answer to
I have spent the last two days looking for a simple javascript or jquery
I've spent the last couple days reading my various books and looking through MSDN's
I spent the last three days working on the collection _ select form helper
I spent hours researching the problem, and just want to share a solution in
I spent the last three days trying to create a small app using SDL
I have spent the last few days attempting to integrate a Grails (version 1.3.2)

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.