2 つのタブを持つサンプル コードがあります。1 つは「フォーム」、もう 1 つは「リスト」(サンプル 1.5-1) を示しています。これらを結合したいと考えています。
「フォーム」タブの下部に「リスト」ビューを表示したい (送信ボタンの後)。これをどう見せようか困っています。
IndexController 内の ->getRequest->isPost() 領域で、$list を作成して埋めようとします (「リスト」タブのサンプル コードと同じ):
$list=$this->_getListRandom();
$this->view->list = $list;
次に、form.phtml 内に以下を追加します。
<h1>My Report Data></h1>
<?php echo $this->list; ?>
Web ページに「My Report Data」というテキストが表示されているので、コードの正しい領域に到達していることがわかります。しかし、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;
}
}