zend框架组件DB找不到类Zend_Paginator_Adapter_DbTableSelect

发布于 2024-09-15 10:55:29 字数 4694 浏览 4 评论 0原文

我在一个小项目中使用 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>

I'm using some Zend libraries outside of the Zend Framework in a small project.
I'm using Zend_Db and Zend_Paginator but when I'm trying to set up the pagination using Zend_Paginator_Adapter_DbTableSelect I get an error that it can't find the class.

Fatal error: Class 'Zend_Paginator_Adapter_DbTableSelect' not found in C:\xampp\htdocs\php_testing\zend\zend_db\index1.php on line 65
Here is my code:

<?
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>';
}
?>

thanks

######### UPDATE EDIT ##########

<?
$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'] ?>">« Prev</a>
    <?php else: ?>
        <span>« 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 »</a>
    <?php else: ?>
        <span>Next »</span>
    <?php endif ?>
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

dawn曙光 2024-09-22 10:55:29

编辑:我认为我的第一个解决方案不会帮助您,除非您可以没有 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));

Edited: I dont think my frirst solution will help you unless you can live without Zend_Paginator_Adapter_DbTableSelect. But looking at your code have you tried including directely DbTableSelect.php?

Try using ::factory.

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


$paginator->setCurrentPageNumber($currentPageNumber);
$paginator->setItemCountPerPage($itemsPerPage);
$scrollType = 'Sliding';
$paginator = get_object_vars($paginator->getPages($scrollType));
宣告ˉ结束 2024-09-22 10:55:29
<?
$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'] ?>">« Prev</a>
    <?php else: ?>
        <span>« 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 »</a>
    <?php else: ?>
        <span>Next »</span>
    <?php endif ?>
</div>
<?
$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'] ?>">« Prev</a>
    <?php else: ?>
        <span>« 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 »</a>
    <?php else: ?>
        <span>Next »</span>
    <?php endif ?>
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文