1

我对 Zend-Framework 的世界还很陌生,并且已经接管了一个使用 zend-framework 的网站。现在其中一个页面上有一个错误,我无法弄清楚。我认为这与 Zend Paginator 有关,但不确定。

这是我遇到问题的部分控制器中的代码:

$currentPage = $this->_getParam('page');
$numWebsitesFullOnline = $websites->getWebsitesFullOnline();

$select = $websites->select();
$select->setIntegrityCheck(false);
$select->from(array('w' => 'websites'), array('id', 'online', 'kw_adjective', 'kw_name', 'kw_location', 'url', 'email', 'address', 'ftp_server', 'ftp_username', 'ftp_password', 'ftp_folder', 'phone_number', 'indexed', 'youtube_position', 'twitter_user', 'facebook_id', 'video_made', 'image1_id', 'image2_id', 'image3_id', 'bg_color', 'dark_color', 'light_color', 'links_color', 'text_color', 'google_account', 'ganalytics', 'gmaps_status', 'google_position', 'gmap_position', 'hp1', 'hp2', 'hp3', 'hp4', 'hp5', 'hp6', 'hp7', 'hp8', 'hp9', 'hp10', 'about1_id', 'about2_id', 'about3_id', 'tip1_id', 'tip2_id', 'tip3_id', 'contact_texts_id', 'quote_texts_id', 'demographics_id'))
    ->join(array('d' => 'demographics'), 'w.demographics_id = d.id', array('total_population'))
    ->order(array('total_population DESC', 'kw_location'));
$paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
$paginator->setItemCountPerPage(50);
$paginator->setCurrentPageNumber($currentPage);
$paginator->setPageRange(($paginator->getTotalItemCount() / 50) + 1);
$this->view->paginator = $paginator;

$numWebsitesOnline = $websites->getWebsitesOnline();

在 php 页面上,我有这段代码可以将数据库中的网站调用到列表中:

<p class="red">
Websites online: <?php echo $this->numOnline; ?>
</p>

<?php print_r(count($this->paginator)); ?>

<?php if(count($this->paginator)): ?>

<table class="table-list">
<?php foreach($this->paginator as $item): ?>
    <tr>
        <?php if($this->userIsAllowedAction('websites', 'reload')): ?>
        <td class="center noborder w30">
            <img class="hidden" src="<?php echo $this->baseUrl() . '/images/loader.gif' ?>" alt="Loading..."/><a class="reload" title="refresh" href="<?php echo $this->baseUrl(); ?>/utils/ui/refresh-website.php" rel="<?php echo urlencode('http://' . $item['url'] . '/install.php'); ?>,<?php echo urlencode($item['ftp_server']); ?>,<?php echo $item['ftp_username']; ?>,<?php echo $item['ftp_password']; ?>,<?php echo $item['ftp_folder']; ?>,<?php echo $this->baseUrl(); ?>,<?php echo $item['id']; ?>"><img src="<?php echo $this->baseUrl(); ?>/images/icon-refresh.png" alt="Refresh"/></a>
        </td>
        <?php endif; ?>
        <td class="center noborder w30">
            <?php if($this->userIsAllowedAction('websites', 'edit')): ?><a title="Edit" href="<?php echo $this->url(array('controller' => 'websites', 'action' => 'edit', 'id' => $item['id'])); ?>"><img src="<?php echo $this->baseUrl(); ?>/images/icon-edit.png" alt="Edit"/></a><?php endif; ?>
        </td>
        <td class="center noborder w30">
            <?php if($this->userIsAllowedAction('websites', 'remove')): ?><a title="Remove" href="<?php echo $this->url(array('controller' => 'websites', 'action' => 'remove', 'id' => $item['id'])); ?>"><img src="<?php echo $this->baseUrl(); ?>/images/icon-delete.png" alt="Remove"/></a><?php endif; ?>
        </td>
        <td>
            <?php if($item['online']): ?>
                <span class="hidden"><?php echo trim($this->escape($item['kw_adjective'] . $item['kw_name'])); ?></span><a class="goto-website" href="http://<?php echo $item['url']; ?>" target="_blank"><?php echo $this->escape($item['kw_location']); ?></a>
            <?php else: ?>
                <?php echo $this->escape($item['kw_location']); ?>
            <?php endif; ?>
        </td>
        <td class="center population">
            <?php if($item['total_population'] >= 0) echo $item['total_population']; ?>
        </td>
        <td class="center">
            <?php if(!empty($item['url'])): ?><img src="<?php echo $this->baseUrl(); ?>/images/check_mark.png" alt="DONE"/><?php endif; ?>
        </td>
        <td class="center">
            <?php if(!empty($item['email'])): ?><img src="<?php echo $this->baseUrl(); ?>/images/check_mark.png" alt="DONE"/><?php endif; ?>
        </td>
        <td class="center">
            <?php if($item['demographics_id']): ?><img src="<?php echo $this->baseUrl(); ?>/images/check_mark.png" alt="DONE"/><?php endif; ?>
        </td>
        <td class="center">
            <?php if($item['hp1'] && $item['hp2'] && $item['hp3'] && $item['hp4'] && $item['hp5'] && $item['hp6'] && $item['hp7'] && $item['hp8'] && $item['hp9'] && $item['hp10'] && $item['about1_id'] && $item['about2_id'] && $item['about3_id'] && $item['tip1_id'] && $item['tip2_id'] && $item['tip3_id'] && $item['contact_texts_id'] && $item['quote_texts_id']): ?><img src="<?php echo $this->baseUrl(); ?>/images/check_mark.png" alt="DONE"/><?php endif; ?>
        </td>
        <td class="center">
            <?php if(file_exists($_SERVER['DOCUMENT_ROOT'] . $this->baseUrl() . Zend_Registry::get('assets_base_path') . '/' . $item['id'] . '/header.jpg')): ?><img src="<?php echo $this->baseUrl(); ?>/images/check_mark.png" alt="DONE"/><?php endif; ?>
        </td>
        <td class="center">
            <?php
                if(($item['bg_color'] != '' && $item['bg_color'] != 'e6e6e6')
                || ($item['dark_color'] != '' && $item['dark_color'] != '003e75')
                || ($item['light_color'] != '' && $item['light_color'] != '3073ad')
                || ($item['links_color'] != '' && $item['links_color'] != '255593')
                || ($item['text_color'] != '' && $item['text_color'] != '4f4f4f')):
            ?>
                <img src="<?php echo $this->baseUrl(); ?>/images/check_mark.png" alt="DONE"/>
            <?php endif; ?>
        </td>
        <td class="center">
            <?php if($item['image1_id'] && $item['image2_id'] && $item['image3_id']): ?><img src="<?php echo $this->baseUrl(); ?>/images/check_mark.png" alt="DONE"/><?php endif; ?>
        </td>
        <td class="center">
            <?php if(!empty($item['twitter_user'])): ?><img src="<?php echo $this->baseUrl(); ?>/images/check_mark.png" alt="DONE"/><?php endif; ?>
        </td>
        <td class="center">
            <?php if(!empty($item['facebook_id'])): ?><img src="<?php echo $this->baseUrl(); ?>/images/check_mark.png" alt="DONE"/><?php endif; ?>
        </td>
        <td class="center">
            <?php if(!empty($item['phone_number'])): ?><img src="<?php echo $this->baseUrl(); ?>/images/check_mark.png" alt="DONE"/><?php endif; ?>
        </td>
        <td class="center">
            <?php if($item['google_account']): ?><img src="<?php echo $this->baseUrl(); ?>/images/check_mark.png" alt="DONE"/><?php endif; ?>
        </td>
        <td class="center">
            <?php if($item['video_made']): ?><img src="<?php echo $this->baseUrl(); ?>/images/check_mark.png" alt="DONE"/><?php endif; ?>
        </td>
        <td class="center">
            <?php if($item['youtube_position']) { echo $item['youtube_position']; }; ?>
        </td>
        <td class="center">
            <?php if(!empty($item['address'])): ?><img src="<?php echo $this->baseUrl(); ?>/images/check_mark.png" alt="DONE"/><?php endif; ?>
        </td>
        <td class="center">
            <?php if($item['gmaps_status'] == 1): ?><img src="<?php echo $this->baseUrl(); ?>/images/icon-gmapspending.png" alt="Pending"/><?php elseif($item['gmaps_status'] == 2): ?><img src="<?php echo $this->baseUrl(); ?>/images/check_mark.png" alt="DONE"/><?php endif; ?>
        </td>
        <td class="center">
            <?php if(!empty($item['ganalytics'])): ?><img src="<?php echo $this->baseUrl(); ?>/images/check_mark.png" alt="DONE"/><?php endif; ?>
        </td>
        <td class="center">
            <?php if($item['online']): ?><img src="<?php echo $this->baseUrl(); ?>/images/check_mark_red.png" alt="Online!"/><?php endif; ?>
        </td>
        <td class="center">
            <?php if($item['indexed']): ?><img src="<?php echo $this->baseUrl(); ?>/images/check_mark_red.png" alt="Online!"/><?php endif; ?>
        </td>
        <td class="center">
            <?php if($item['gmap_position']) { echo $item['gmap_position']; }; ?>
        </td>
        <td class="center">
            <?php if($item['google_position']) { echo $item['google_position']; }; ?>
        </td>
    </tr>
<?php endforeach; ?>
</table>
<?php endif; ?>

print_r(count($this->paginator)); 行返回“0”,$this->numOnline; 行返回 1。所以它看到数据库的网站表中有一行,但它没有返回任何内容到页面并列出网站表中的行。不确定这是否是导致此原因的分页器返回 0 或我不知道的其他内容。

4

1 回答 1

1

我不确定,但尝试使用 joinLeft 而不是 join,也许只是网站表和人口统计表之间的关系导致了这个结果。

于 2013-06-30T22:57:27.413 回答