将项目添加到已创建的 Zend_Paginator 中?

发布于 2024-08-20 12:52:58 字数 1677 浏览 8 评论 0原文

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

// 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);

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

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

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

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

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: If someone could tell me how to format correctly php code in Stackoverflow it would be helpful :-).

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

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

发布评论

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

评论(1

天涯离梦残月幽梦 2024-08-27 12:52:58

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

    // 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);
    }

有点晚了,但我希望这对您有所帮助,也许对其他可能有类似问题的人有所帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文