Php Zend Paginator变量
我试图使用Php Zend Paginator变量,php,zend-framework,pagination,zend-paginator,Php,Zend Framework,Pagination,Zend Paginator,我试图使用Zend_Paginator和Zend_Db_Table_Abstract来获取数据行集 我在从变量接收数据时遇到了问题 我的错误内容 “致命错误:无法将Zend_Paginator类型的对象用作第8行C:\xampp\htdocs\applications\quickstart\application\views\scripts\index\text.phtml中的数组” Text.php: class Application_Model_Text extends Zend_Db_T
Zend_Paginator
和Zend_Db_Table_Abstract
来获取数据行集
我在从变量接收数据时遇到了问题
我的错误内容
“致命错误:无法将Zend_Paginator类型的对象用作第8行C:\xampp\htdocs\applications\quickstart\application\views\scripts\index\text.phtml中的数组”
Text.php:
class Application_Model_Text extends Zend_Db_Table_Abstract
{
protected $_name = 'text';
public function getTexts($page)
{
$query = $this->select();
$paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($query));
$paginator->setCurrentPageNumber($page)->setItemCountPerPage(2);
return $paginator;
}
}
IndexController.php:
public function textAction()
{
$page = $this->getParam('page');
$textModel = new Application_Model_Text();
$data = $textModel->getTexts($page);
$this->view->text = $data;
}
pagination.phtml:
<div id="pagination">
<?php $pageVariable = ($this->page)?$this->page: 'page' ?>
<a href="<?= $this->url(array($pageVariable => $this->previous)) ?>">Back</a>
<p>Strona <?= $this->current ?></p>
<a href="<?= $this->url(array($pageVariable => $this->next)) ?>">Next</a>
</div>
斯特罗纳
text.phtml:
<?php $text = $this->text; ?>
<div id="pagination-box">
<?= $this->paginationControl($text, 'Sliding', array('pagination.phtml', 'default')) ?>
</div>
<div>
<div id="text">
<p><?= $text['text'] ?></p>
</div>
</div>
有人知道我做错了什么吗?我是Zend的新手,但我非常喜欢这个框架。
提前感谢您的帮助:)Zend paginator返回行集数组,因此在
索引中.phtml
文件$text
不是数组,而是对象。尝试使用属性,例如:
<?= $text->text; ?>
更改:
<div id="text">
<p><?= $text['text'] ?></p>
</div>
To('text'是一组项目,因此需要迭代):
我已经尝试过了,我得到了:
注意:未定义的属性:Zend_Paginator::$text在C:\xampp\htdocs\applications\quickstart\application\views\scripts\index\text.phtml的第7行
<?php foreach($text as $row):?>
<div id="text">
<?= $row->text ?>
</div>
<?php endforeach ?>