如何将表单和列表添加到$ this [Plesk / Zend]

时间:2013-07-03 21:49:04

标签: zend-framework plesk

我有一些带有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;
    }
}

1 个答案:

答案 0 :(得分:0)

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

以下文件已更改:

\例如-1.5-2 \ PLIB \视图\脚本\指数\ form.phtml:

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

\例如-1.5-2 \ PLIB \控制器\ IndexController.php:

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

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

这里的结果是:

enter image description here