简体   繁体   English

CakePHP 1.2分页链接已禁用

[英]CakePHP 1.2 pagination link is disabled

In my CakePHP application, my custom pagination is not working at all. 在我的CakePHP应用程序中,我的自定义分页根本不起作用。 There are three problems I'm facing: 我面临三个问题:

  1. It's always showing only a single page 它总是只显示一个页面
  2. Links are disabled 链接被禁用
  3. Ending record is incorrect. 结束记录不正确。 I have total 7 records. 我总共有7条记录。 I used LIMIT 3 , so only 3 records should be visible per page, the last record being record no. 我使用了LIMIT 3 ,因此每页仅3条记录可见,最后一条记录为no。 3 in the first page. 第一页中的3。 But instead, record no. 但是,请记录为否。 7 is being displayed as the ending record in the first page. 第一页中将显示7作为结束记录。

I have set debug mode to 2 to try to find out any problems that may exist in my code. 我将debug mode设置为2以尝试找出代码中可能存在的任何问题。 But was unable to find any. 但找不到任何东西。

Here's my controller code: 这是我的控制器代码:

var $name = 'HomeLoanDistributions';

function index() {
        $user = $this->Session->read('User');
        $user_role = $user['User']['user_role_id'];
        $actions = $this->Session->read('actions');
        $display_actions = array();

        foreach ($actions as $action) {
            array_push($display_actions, $action['pm_controller_actions']['name']);
        }
        $this->set('display_actions', $display_actions);
        $this->set('user_role', $user_role);


        $branch_id = $this->branchCheck();
        $this->set('branch_id', $branch_id);
        $conditions = array('branch_id' => $branch_id);

        $this->set('HomeLoanDistributions', $this->paginate($conditions));
        $this->HomeLoanDistribution->Branch->recursive = 0;
        $this->set('BranchInformation', $this->HomeLoanDistribution->Branch->read(array('Branch.id', 'Branch.name', 'Region.name', 'District.name', 'SubDistrict.name', 'Cluster.name'), $branch_id));
    }

function branchCheck() {
        // check for matching branch

        if (isset($this->params['named']['branch_id'])) {


            if (empty($this->params['named']['branch_id'])) {
                $this->Session->setFlash(__('Branch could not be found. Please, try again.', true));
                $this->redirect(array('controller' => 'Branches', 'action' => 'index', $this->name));
            } else {
                $this->HomeLoanDistribution->Branch->recursive = -1;

                if ($this->HomeLoanDistribution->Branch->find('count', array('conditions' => array('Village.id' => $this->params['named']['branch_id']))) != 1) {

                    $this->Session->setFlash(__('The Branch could not be found. Please, try again.', true));
                    $this->redirect(array('controller' => 'Branches', 'action' => 'index', $this->name));
                }
            }
            return $this->params['named']['branch_id'];
        }
    }

Here's my model code: 这是我的模型代码:

 var $name = 'HomeLoanDistribution';
    var $actsAs = array('Logable' => array(
            'userModel' => 'User',
            'userKey' => 'user_id',
            'change' => 'list', // options are 'list' or 'full'
            'description_ids' => TRUE // options are TRUE or FALSE
    ));
    var $validate = array(
        'entry_date' => array(
            'rule' => 'date',
            'message' => 'Enter a valid date',
            'allowEmpty' => true
        ),
        'branch_id' => array('numeric'),
        'customer_id' => array('numeric'),
        'home_group_id' => array('numeric'),
        'voucher_no' => array('numeric'),
        'no_of_installment' => array('numeric'),
        'loan_amount' => array('numeric'),
        'service_charge' => array('numeric'),
        'security' => array('numeric'),
        'loan_taken_term' => array('numeric'),
        'installment_amount' => array('numeric'),
        'installment_service_charge' => array('numeric'),
        'effective_date' => array('numeric'),
    );

    var $belongsTo = array(
        'Branch' => array(
            'className' => 'Branch',
            'foreignKey' => 'branch_id',
            'conditions' => '',
            'fields' => 'id,name',
            'order' => ''
        ),
    );
function paginate($conditions, $fields, $order, $page = 1, $recursive = null, $extra = array()) {

    $recursive = 0;

    $fields =  array('entry_date');
    $group = array('branch_id');
    $order = array('entry_date DESC');
    $limit = 3;
    return $this->find('all', compact('fields', 'order', 'limit', 'page', 'recursive', 'group'));
    $this->paginateCount($conditions);
}

function paginateCount($conditions = null, $recursive = 0, $extra = array()) {

    $recursive = 0;
    $fields =  array('entry_date');
    $group = array('branch_id');
    $order = array('entry_date DESC');
    $results = $this->find('all', compact('fields', 'order', 'limit', 'page', 'recursive', 'group'));
    return count($results);
}

And my view codes: 我的查看代码:

    <?php echo $this->renderElement('BranchInformation'); ?>
    <?php
    $paginator->options(
            array(
                'url' => array('controller' => 'HomeLoanDistributions', 'action' => $this->action, 'branch_id' => $BranchInformation['Branch']['id'])));
    ?>
    <h2><?php __('Home Loan Distribution'); ?></h2>
    <table cellpadding="0" cellspacing="0">
        <tr>
            <th><?php echo 'SL NO.'; ?></th>
            <th><?php echo $paginator->sort('Loan Distribution Month', 'entry_date'); ?></th>

            <th class="actions"><?php __('Actions'); ?></th>
            <!--th class="actions"><--?php __('Actions');?></th-->
        </tr>
        <?php

        $start = (int) $paginator->counter('%start%');
        $i = 0;
        foreach ($HomeLoanDistributions as $HomeLoanDistribution):
            $class = null;
            if ($i++ % 2 == 0) {
                $class = ' class="altrow"';
            }

            ?>
            <tr<?php echo $class; ?>>
                <td>
                    <?php echo $start++; ?>
                </td>
                <td class="taRight">
                    <?php
                    $returnDate = date_format(date_create($HomeLoanDistribution['HomeLoanDistribution']['entry_date']), "M-Y");
                    print_r($returnDate);
                    ?>
                </td>

                <td class="actions">
                    <?php echo $html->link(__('View', true), array('action' => 'view', $HomeLoanDistribution['HomeLoanDistribution']['entry_date'], 'branch_id' => $BranchInformation['Branch']['id'])); ?>
                    <?php echo $html->link(__('Edit', true), array('action' => 'edit', $HomeLoanDistribution['HomeLoanDistribution']['entry_date'], 'branch_id' => $BranchInformation['Branch']['id'])); ?>
                    <?php echo $html->link(__('Delete', true), array('action' => 'delete', $HomeLoanDistribution['HomeLoanDistribution']['entry_date'], 'branch_id' => $BranchInformation['Branch']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $HomeLoanDistribution['HomeLoanDistribution']['entry_date'])); ?>
                </td>
            </tr>
        <?php endforeach; ?>
    </table>
</div>
<div class="paging">
    <?php echo $paginator->prev('<< ' . __('previous', true), array(), null, array('class' => 'disabled')); ?>  
    <?php echo $paginator->numbers(); ?>
    <?php echo $paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled')); ?>
    <span style="float:right;"><?php
        echo $paginator->counter(array(
            'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
        ));
        ?></span>
</div>

My CakePHP version is 1.2.5 and my PHP version is 5.2.11, since this is a very old project back from 2008-09. 我的CakePHP版本是1.2.5,我的PHP版本是5.2.11,因为这是2008-09年以来的一个非常老的项目。

When he called: 当他打电话时:

$this->set('HomeLoanDistributions', $this->paginate($conditions));

I think he used : http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html 我认为他使用过: http : //book.cakephp.org/2.0/en/core-libraries/components/pagination.html

and $limit should be passed in configuration of PaginationComponent .. isnt it ? 和$ limit应该在PaginationComponent的配置中传递。

does there are $paginate var in AppController or in this one ? 在AppController或此控制器中是否有$ paginate var?


Edit : try use paginate from your MOdel : 编辑:尝试使用MOdel中的分页:

Change 更改

$this->set('HomeLoanDistributions', $this->paginate($conditions));

by 通过

$this->set('HomeLoanDistributions', $this->HomeLoanDistribution->paginate($conditions) ); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM