【问题标题】:Zend Paginator variableZend Paginator 变量
【发布时间】:2014-09-26 10:03:36
【问题描述】:

我正在尝试使用 Zend_PaginatorZend_Db_Table_Abstract 来获取数据行集。

我在从变量接收数据时遇到了问题。

我的错误内容

"致命错误: 不能在第 8 行的 C:\xampp\htdocs\applications\quickstart\application\views\scripts\index\text.phtml 中使用 Zend_Paginator 类型的对象作为数组"

文本.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;
}

分页.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>

文本.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 的新手,但我真的很喜欢这个框架。
在此先感谢您的帮助:)

【问题讨论】:

    标签: php zend-framework pagination zend-paginator


    【解决方案1】:

    变化:

    <div id="text">
        <p><?= $text['text'] ?></p>
    </div>
    

    To('text' 是一组项目,所以你需要迭代):

    <?php foreach($text as $row):?>
      <div id="text">
      <?= $row->text ?>
      </div>
    <?php endforeach ?>
    

    【讨论】:

      【解决方案2】:

      Zend 分页器返回行集数组,所以在你的index.phtml 文件中$text 不是一个数组,它是一个对象。尝试使用属性,例如:

      <?= $text->text; ?>
      

      【讨论】:

      • 我已经尝试过了,我得到了:
        注意:未定义的属性:C:\xampp\htdocs\applications\quickstart\application\views\scripts 中的 Zend_Paginator::$text \index\text.phtml 第 7 行
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-14
      • 1970-01-01
      • 1970-01-01
      • 2013-06-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多