开发者

Adding items to a Zend_Paginator already created?

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 :-).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜