zend框架组件DB找不到类Zend_Paginator_Adapter_DbTableSelect

时间:2010-08-24 16:53:16

标签: zend-framework pagination zend-db-table zend-paginator

我在一个小项目中使用Zend Framework之外的一些Zend库。 我正在使用Zend_DbZend_Paginator但是当我尝试使用Zend_Paginator_Adapter_DbTableSelect设置分页时,我收到一个无法找到类的错误。

  

致命错误:第65行的C:\ xampp \ htdocs \ php_testing \ zend \ zend_db \ index1.php中找不到类'Zend_Paginator_Adapter_DbTableSelect'   这是我的代码:

<?
require_once 'Zend/Db.php';
$config=array(
    'adapter' => 'PDO_MYSQL',
    'hostname' => 'localhost',
    'dbname' => 'dm_xxxx',
    'username' => 'un',
    'password' => 'pw'

);
$db=Zend_Db::factory($config['adapter'], $config);
$select=$db->select()
        ->from('photocontest__photos', array('*'))
        ->order('created')
        ;    
require_once 'Zend/Paginator.php';
$currentPageNumber = ($_GET['page'] > 0)?$_GET['page']:'1';
$totalNumberOfItems = 11;
$itemsPerPage = 5;
$pageRange = 10;

$adapter = new Zend_Paginator_Adapter_DbTableSelect($select);
$paginator = new Zend_Paginator($adapter);
$paginator->setCurrentPageNumber($currentPageNumber);
$paginator->setItemCountPerPage($itemsPerPage);
$scrollType = 'Sliding';
$paginator = get_object_vars($paginator->getPages($scrollType));

foreach($paginator AS $item){
    echo $item->title.'<br>';
}
?>

感谢

#########更新编辑##########

<?
$config=array(
    'adapter' => 'PDO_MYSQL',
    'hostname' => 'localhost',
    'dbname' => 'dm_xxxx',
    'username' => 'un',
    'password' => 'pw'

);
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
$db=Zend_Db::factory($config['adapter'], $config);
$table = new Photos(array('db' => $db));
$select = $table->select();
$select->setIntegrityCheck(false)
        ->from('photocontest__photos', array('*'))
        ->order('created')
        ;       

$currentPageNumber = ($_GET['page'] > 0)?$_GET['page']:'1';
$itemsPerPage = 6;
$adapter = new Zend_Paginator_Adapter_DbTableSelect($select); //Setup the adapter object
$paginator = new Zend_Paginator($adapter); //Setup the actual paginator object

$paginator->setCurrentPageNumber($currentPageNumber);
$paginator->setItemCountPerPage($itemsPerPage); // items pre page

$scrollType = 'Sliding'; //change this to 'All', 'Elastic', 'Sliding' or 'Jumping' to test all scrolling types

Zend_Paginator::setDefaultScrollingStyle('Sliding'); // Sliding  or  Elastic
//Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');

$paginatorControl = get_object_vars($paginator->getPages($scrollType)); //and that's it! we can now use the $paginator variable as we want
?>
<h1>Zend_Paginator Demo</h1>
<ul id="items">
    <?php foreach($paginator AS $item): ?>
        <li><?php echo $item->title; ?></li>
    <?php endforeach ?>
</ul>

<div id="paginator">
    <p>Showing <strong><?php echo $paginatorControl['firstItemNumber'] ?> to <?php echo $paginatorControl['lastItemNumber'] ?></strong> out of <strong><?php echo $paginatorControl['totalItemCount'] ?></strong> items</p>

    <?php if($paginatorControl['previous']): ?>
        <a href="?page=<?php echo $paginatorControl['previous'] ?>">&laquo; Prev</a>
    <?php else: ?>
        <span>&laquo; Prev</span>
    <?php endif ?>

    <?php if($paginatorControl['firstPageInRange'] > $paginatorControl['first']): ?>
        <a href="?page=<?php echo $paginatorControl['first'] ?>"><?php echo $paginatorControl['first'] ?></a>
        <span>...</span>
    <?php endif ?>

    <?php foreach($paginatorControl['pagesInRange'] as $page): ?>
        <?php if($page == $paginatorControl['current']): ?>
            <span><?php echo $page ?></span>
        <?php else: ?>
            <a href="?page=<?php echo $page ?>"><?php echo $page ?></a>
        <?php endif ?>
    <?php endforeach ?>

    <?php if($paginatorControl['lastPageInRange'] < $paginatorControl['last']): ?>
        <span>...</span>
        <a href="?page=<?php echo $paginatorControl['last'] ?>"><?php echo $paginatorControl['last'] ?></a>
    <?php endif ?>

    <?php if($paginatorControl['next']): ?>
        <a href="?page=<?php echo $paginatorControl['next'] ?>">Next &raquo;</a>
    <?php else: ?>
        <span>Next &raquo;</span>
    <?php endif ?>
</div>

2 个答案:

答案 0 :(得分:0)

编辑:我不认为我的第一个解决方案会帮助你,除非你没有Zend_Paginator_Adapter_DbTableSelect。但是看看你的代码,你试过直接包括DbTableSelect.php吗?

尝试使用:: factory。

$paginator = Zend_Paginator::factory($adapter);


$paginator->setCurrentPageNumber($currentPageNumber);
$paginator->setItemCountPerPage($itemsPerPage);
$scrollType = 'Sliding';
$paginator = get_object_vars($paginator->getPages($scrollType));

答案 1 :(得分:0)

<?
$config=array(
    'adapter' => 'PDO_MYSQL',
    'hostname' => 'localhost',
    'dbname' => 'dm_xxxx',
    'username' => 'un',
    'password' => 'pw'

);
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
$db=Zend_Db::factory($config['adapter'], $config);
$table = new Photos(array('db' => $db));
$select = $table->select();
$select->setIntegrityCheck(false)
        ->from('photocontest__photos', array('*'))
        ->order('created')
        ;       

$currentPageNumber = ($_GET['page'] > 0)?$_GET['page']:'1';
$itemsPerPage = 6;
$adapter = new Zend_Paginator_Adapter_DbTableSelect($select); //Setup the adapter object
$paginator = new Zend_Paginator($adapter); //Setup the actual paginator object

$paginator->setCurrentPageNumber($currentPageNumber);
$paginator->setItemCountPerPage($itemsPerPage); // items pre page

$scrollType = 'Sliding'; //change this to 'All', 'Elastic', 'Sliding' or 'Jumping' to test all scrolling types

Zend_Paginator::setDefaultScrollingStyle('Sliding'); // Sliding  or  Elastic
//Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');

$paginatorControl = get_object_vars($paginator->getPages($scrollType)); //and that's it! we can now use the $paginator variable as we want
?>
<h1>Zend_Paginator Demo</h1>
<ul id="items">
    <?php foreach($paginator AS $item): ?>
        <li><?php echo $item->title; ?></li>
    <?php endforeach ?>
</ul>

<div id="paginator">
    <p>Showing <strong><?php echo $paginatorControl['firstItemNumber'] ?> to <?php echo $paginatorControl['lastItemNumber'] ?></strong> out of <strong><?php echo $paginatorControl['totalItemCount'] ?></strong> items</p>

    <?php if($paginatorControl['previous']): ?>
        <a href="?page=<?php echo $paginatorControl['previous'] ?>">&laquo; Prev</a>
    <?php else: ?>
        <span>&laquo; Prev</span>
    <?php endif ?>

    <?php if($paginatorControl['firstPageInRange'] > $paginatorControl['first']): ?>
        <a href="?page=<?php echo $paginatorControl['first'] ?>"><?php echo $paginatorControl['first'] ?></a>
        <span>...</span>
    <?php endif ?>

    <?php foreach($paginatorControl['pagesInRange'] as $page): ?>
        <?php if($page == $paginatorControl['current']): ?>
            <span><?php echo $page ?></span>
        <?php else: ?>
            <a href="?page=<?php echo $page ?>"><?php echo $page ?></a>
        <?php endif ?>
    <?php endforeach ?>

    <?php if($paginatorControl['lastPageInRange'] < $paginatorControl['last']): ?>
        <span>...</span>
        <a href="?page=<?php echo $paginatorControl['last'] ?>"><?php echo $paginatorControl['last'] ?></a>
    <?php endif ?>

    <?php if($paginatorControl['next']): ?>
        <a href="?page=<?php echo $paginatorControl['next'] ?>">Next &raquo;</a>
    <?php else: ?>
        <span>Next &raquo;</span>
    <?php endif ?>
</div>