Reputation: 21
I'm trying to use Zend_Paginator
with Zend_Db_Table_Abstract
to get data rowset.
I've faced with problem in receive data from variable.
My error content
"Fatal error: Cannot use object of type Zend_Paginator as array in C:\xampp\htdocs\applications\quickstart\application\views\scripts\index\text.phtml on line 8"
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>
Anyone has idea what I'm doing wrong?
I'm new to Zend but I really enjoy that framework.
In advance thank's for the help :)
Upvotes: 2
Views: 276
Reputation: 1649
Change:
<div id="text">
<p><?= $text['text'] ?></p>
</div>
To ('text' is a set of items so you need to iterate) :
<?php foreach($text as $row):?>
<div id="text">
<?= $row->text ?>
</div>
<?php endforeach ?>
Upvotes: 2
Reputation: 21957
Zend paginator returns array of rowsets, so in your index.phtml
file $text
is not an array, it is an object. Try to work with properties, like:
<?= $text->text; ?>
Upvotes: 0