2013-07-03 26 views
0

我有一些帶有2個選項卡的示例代碼。一個顯示一個「表格」,另一個顯示「列表」(樣本1.5-1),我想合併它們。

我想在底部(提交按鈕後)顯示「表單」選項卡的「列表」視圖。我陷入瞭如何展示這一點。

裏面的IndexController,在 - > getRequest-> isPost()方面,我嘗試創建和填補$列表(同爲 「列表」 選項卡中的示例代碼):內

$list=$this->_getListRandom(); 
$this->view->list = $list; 

然後form.phtml的,我附上:

<h1>My Report Data></h1> 
<?php echo $this->list; ?> 

我可以看到網頁中的「我的報告數據」文本,所以我知道我正在給代碼正確的區域! 但是,我從pm_View_Helper_render :: renderList()得到一個錯誤,它必須是pm_View_List_Simple的一個實例。

我想在同一個$ this中創建pm_Form_Simple和pm_View_List_Simple,但不是 確定是否允許或者如何執行。

感謝您的任何建議!

<?php 

class IndexController extends pm_Controller_Action 
{ 
    public function init() 
    { 
     parent::init(); 

     // Init title for all actions 
     $this->view->pageTitle = 'Example Module'; 

     // Init tabs for all actions 
     $this->view->tabs = array(
      array(
       'title' => 'Form', 
       'action' => 'form', 
      ), 
      array(
       'title' => 'List', 
       'action' => 'list', 
      ), 
     ); 
    } 

    public function indexAction() 
    { 
     // Default action will be formAction 
     $this->_forward('form'); 
    } 

    public function formAction() 
    { 
     // Init form here 
     $form = new pm_Form_Simple(); 
     $form->addElement('text', 'exampleText', array(
      'label' => 'Example Text', 
      'value' => pm_Settings::get('exampleText'), 
      'required' => true, 
      'validators' => array(
       array('NotEmpty', true), 
      ), 
     )); 

     $form->addControlButtons(array(
      'cancelLink' => pm_Context::getModulesListUrl(), 
     )); 

     if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) { 

      // Form proccessing here 
      pm_Settings::set('exampleText', $form->getValue('exampleText')); 

      $this->_status->addMessage('info', 'Data was successfully saved.'); 

      # Create the LIST 
      $list = $this->_getListRandom(); 
      $this->view->list = $list; 

      $this->_helper->json(array('redirect' => pm_Context::getBaseUrl())); 
     } 

     $this->view->form = $form; 
    } 

    public function listAction() 
    { 
     $list = $this->_getListRandom(); 

     // List object for pm_View_Helper_RenderList 
     $this->view->list = $list; 
    } 

    public function listDataAction() 
    { 
     $list = $this->_getListRandom(); 

     // Json data from pm_View_List_Simple 
     $this->_helper->json($list->fetchData()); 
    } 

    private function _getListRandom() 
    { 
     $data = array(); 
     #$iconPath = pm_Context::getBaseUrl() . 'images/icon_16.gif'; 
     for ($i = 0; $i < 15; $i++) { 
      $data[] = array(
       'column-1' => '<a href="#">' . (string)rand() . '</a>', 
       'column-2' => (string)rand(), 
      ); 
     } 

     $list = new pm_View_List_Simple($this->view, $this->_request); 
     $list->setData($data); 
     $list->setColumns(array(
      'column-1' => array(
       'title' => 'Random with link', 
       'noEscape' => true, 
      ), 
      'column-2' => array(
       'title' => 'Random with image', 
       'noEscape' => true, 
      ), 
     )); 
     // Take into account listDataAction corresponds to the URL /list-data/ 
     $list->setDataUrl(array('action' => 'list-data')); 

     return $list; 
    } 
} 
+0

你說你從'pm_View_Helper_render'得到一個錯誤,但是這不是在您發佈的代碼的任何地方調用。你在form.phtml的其他地方叫嗎? –

+0

哎呀,它一定是被緩存了......(plesk似乎這樣做)。我現在沒有得到任何錯誤,但我也沒有得到「列表」控制... – user589310

回答

0

請嘗試https://mega.co.nz/#!NxtyzbyS!JQqFdh7ruESQU_pgmhM6vi8yVFZQRTH-sPDeQcAOFws

下列文件被更改:

\例如,1.5-2 \ PLIB \意見\腳本\首頁\ form.phtml:

​​

\ example-1.5-2 \ plib \ controllers \ IndexController.php:

public function formAction() { 
     ... 
     ... 
     ... 
     $list = $this->_getListRandom(); 

     // List object for pm_View_Helper_RenderList 
     $this->view->list = $list; 
} 

這裏的結果:

enter image description here

+0

非常感謝您的回覆。我一直被鎖在myopenid登錄幾天...所以只想說非常感謝! – user589310