0

我是这些技术的新手,所以可能不是要求这样做最简单的方法,但是:我想创建一个表单并要求一个 ID 值。按下提交后,我想获取该 ID,进行外部 XML 调用,然后显示 XML 数据。如果我可以在单个 url 中执行此操作,我会坚持下去:https://plesk.local:8443/modules/example/index.php/index/form。我想在同一页面上同时拥有表单和列表数据,这样我就可以更新 ID,按提交并查看新数据......一遍又一遍......

我正在尝试修改 Plesk 包含的基本“Example1”。我可以对其进行修改和测试,但仍坚持 POST 的工作原理。理想情况下,我希望 $this->view->form 在同一个 $form 视图上同时拥有 pm_Form_Simple 和 pm_View_List_Simple (如果这有意义的话)。

所以寻求帮助 1) 我可以使用相同的 URL 并从中处理 POST/GET 2) 我可以在同一页面上同时拥有表单和简单列表吗?

谢谢!!!!!

这是示例控制器:

<?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.');
            $this->_helper->json(array('redirect' => pm_Context::getBaseUrl()));
        }

    # NEW - start
    if (0)
    {
        # I want to be back here after the POST
        # Want to show the list here after I take the POST parameter and do an external XML call...
        $list = $this->_getListRandom();
        $this->view->list = $list;
    }
    # NEW - end

        $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
  1. 是的
  2. 是的

我对zend没有经验,所以它只是尝试,我建议用以下代码替换formAction():

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.');

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

        // Redirects happens on next string, maybe you need to add something to getBaseUrl()
        $this->_helper->json(array('redirect' => pm_Context::getBaseUrl()));
    }

$this->view->form = $form;
}
于 2013-07-03T12:52:09.790 回答