0

我有一些带有 2 个选项卡的示例代码。一个显示“表格”,另一个显示“列表”(示例 1.5-1),我想将它们结合起来。

我想在底部显示带有“列表”视图的“表单”选项卡(在提交按钮之后)。我被困在如何展示这一点上。

在 IndexController 内部,在 ->getRequest->isPost() 区域中,我尝试创建并填充 $list(与“list”选项卡示例代码相同):

$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;
    }
}
4

1 回答 1

0

请尝试https://mega.co.nz/#!NxtyzbyS!JQqFdh7ruESQU_pgmhM6vi8yVFZQRTH-sPDeQcAOFws

以下文件已更改:

\example-1.5-2\plib\views\scripts\index\form.phtml:

<?php echo $this->renderTabs($this->tabs); ?>
<?php echo $this->test; ?>
<?php echo $this->form; ?>
<?php echo $this->renderList($this->list); ?>

\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;
}

结果如下:

在此处输入图像描述

于 2013-07-04T04:07:29.597 回答