Zend framework 如何将表单和列表添加到$this[Plesk/Zend]
我有一些带有两个选项卡的示例代码。一个显示一个“表单”,另一个显示一个“列表”(示例1.5-1),我想将它们结合起来 我想显示底部带有“列表”视图的“表单”选项卡(在提交按钮之后)。我被困在如何展示这一点上 在IndexController中的->getRequest->isPost()区域中,我尝试创建并填充$list(与“list”选项卡示例代码相同): 然后在form.phtml中,我附加:Zend framework 如何将表单和列表添加到$this[Plesk/Zend],zend-framework,plesk,Zend Framework,Plesk,我有一些带有两个选项卡的示例代码。一个显示一个“表单”,另一个显示一个“列表”(示例1.5-1),我想将它们结合起来 我想显示底部带有“列表”视图的“表单”选项卡(在提交按钮之后)。我被困在如何展示这一点上 在IndexController中的->getRequest->isPost()区域中,我尝试创建并填充$list(与“list”选项卡示例代码相同): 然后在form.phtml中,我附加: <h1>My Report Data></h1> <?php
<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.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); ?>
结果如下:
您说您从
pm\u View\u Helper\u render
中得到一个错误,但在您发布的代码中没有调用该错误。你会在form.phtml的其他地方调用它吗?哎呀,它一定已经被缓存了…(plesk似乎是这么做的)。我现在没有收到任何错误,但是我也没有收到“列表”控件…非常感谢您的回复。我已经有好几天没有登录myopenid了…所以我想说声非常感谢!
<?php echo $this->renderTabs($this->tabs); ?>
<?php echo $this->test; ?>
<?php echo $this->form; ?>
<?php echo $this->renderList($this->list); ?>
public function formAction() {
...
...
...
$list = $this->_getListRandom();
// List object for pm_View_Helper_RenderList
$this->view->list = $list;
}