2010-02-05 84 views
1

在我的控制器我已經創建了一個分頁程序實例是這樣的:添加項目到已經創建的Zend_Paginator?

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

但在我控制我會處理一些條件。我的paginator實例是項目版本的集合。所以我會處理,如果主目錄已被正確創建,如果有關版本的信息已正確插入數據庫...所有在控制器中檢查。 我的目標是添加這些變量(大部分時間爲布爾值)並將其添加到paginator實例,然後我將在視圖中迭代它並添加消息錯誤。

PS:如果有人能告訴我如何在Stackoverflow中正確地格式化PHP代碼,那將是有益的:-)。

+0

標有'010'的編輯屏幕的菜單欄中有一個按鈕。選擇代碼並按下按鈕。 SO使用Markdown進行文本格式化,因此您可以使用http://daringfireball.net/projects/markdown/syntax – Gordon 2010-02-06 22:37:33

+0

中給出的語法。不幸的是,我不明白主要問題。 – Gordon 2010-02-06 22:40:18

回答

1

我認爲應該有可能爲您的分頁程序中的項目添加值。但是,確切的方法將取決於您在分頁程序中使用的適配器。作爲示例,我將提供一個片段,演示如何向使用數組適配器的分頁程序中的項目添加值。

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

有點晚了,但我希望這會對你有幫助,如果不是對你有幫助,也許對其他一些可能有類似問題的人有幫助。

+0

由於PHP 5.2x這不會工作:( – bksi 2013-02-18 00:01:21

相關問題