向已创建的 Zend_Paginator 添加项目? [英] Adding items to a Zend_Paginator already created?

查看:26
本文介绍了向已创建的 Zend_Paginator 添加项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的控制器中,我创建了一个这样的分页器实例:

in my controller I have created a paginator instance like this:

// On crée un objet paginator pour afficher un tableau de résultat.
$paginator = Zend_Paginator::factory($versions->getVersions($projectId));
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(15);

然后我像这样在我的视图中迭代:

Then I iterate over in my view like this:

<? foreach ($this->paginator as $item): ?>
    <? ($flag == "pair") ? $flag = "impair" : $flag = "pair"; ?>
    <tr class="<?= $flag; ?>">
        <!-- version nom de la version -->
        <td>
            <a href="<?= $this->url(array('module' => "admin", 'controller' => "version", 'action' => "index", 'project' => $item['idversion'])); ?>">
                <?= $item['lab_version']; ?>
            </a>
        </td>
        <!-- version nom du project -->
        <td><?= $item['name_patrimony']; ?></td>
        <!-- version retrodocumente ? -->
        <td class="version-retrodoc">
            <a href="<?= $this->url(array("module" => "doxygen", "controller" => "doxygen", "action" => "create", "version" => $item['idversion']), null, true); ?>">
                <img src="<?= $this->baseUrl() . '/img/system-run.png' ?>" alt="retrodocumenté"/>
             </a>
        </td>
    </tr>
<? endforeach; ?>

但在我的控制器中,我会处理一些条件.我的分页器实例是项目版本的集合.因此,如果有关版本的信息正确插入到数据库中,我会处理是否已正确创建主目录......所有这些都在控制器中检查.我的目标是添加这些变量(大部分时间是布尔值)并将其添加到分页器实例中,然后我将在视图中对其进行迭代并添加消息错误.

But in my controller I would handle some conditions. My paginator instance is a collection of version of project. So I would handle if the home directory has been correctly created if the information about the version is correctly inserted in the db... All that are checking in the controller. My goal is to add these variables (most of the times boolean) and add it to paginator instance so then I would iterate over it in the view and add message error.

PS:如果有人能告诉我如何在 Stackoverflow 中正确格式化 php 代码,那会很有帮助:-).

PS: If someone could tell me how to format correctly php code in Stackoverflow it would be helpful :-).

推荐答案

我认为应该可以为分页器中的项目添加值.但是,确切的方法将取决于您在分页器中使用的适配器.例如,我将提供一个片段,展示如何向使用数组适配器的分页器中的项目添加值.

I think it should be possible to add a value to an item in your paginator. However, the exact methodology will depend on your adapter that you use in the paginator. As as example, I'll provide a snippet that shows how to add a value to an item in a paginator that uses array adapter.

    // somewhere in your controller:

    $input = array(
        array(
            'firstname' => 'somename',
            'lastname' => 'somelastname',
            'location' => 'somelocation'
        ),
        array(
            'firstname' => 'somename2',
            'lastname' => 'somelastname2',
            'location' => 'somelocation2'
        )
    );

    $paginator = Zend_Paginator::factory($input);
    $paginator->setCurrentPageNumber(1);

    foreach ($paginator as $key => &$value) {

        // performe some logic to check if the home directory has been correctly created
        // and the boolean value to represent this (in this example it is always false).
        $value['newVariable'] = false;
        var_dump($value);
    }

有点晚了,但我希望这对你有帮助,也许对其他一些可能有类似问题的人有帮助.

Little late, but I hope that this will helpful if not to you, maybe to some other people that may have similar problem.

这篇关于向已创建的 Zend_Paginator 添加项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆