我正在嘗試基於magento模型製作真正的網格。 在閱讀部分,一切都運行良好,但編輯窗體沒有呈現,我在日誌中沒有錯誤。 我注意到我的_prepareForm函數從來沒有被調用,但我不知道爲什麼。Magento Form Block未呈現
我的形式呼叫控制器:
public function editAction()
{
$this->_initAction();
// Get id if available
$id = $this->getRequest()->getParam('contact_request_id');
$model = Mage::getModel('whatever_booking/contactRequest');
if ($id) {
// Load record
$model->load($id);
// Check if record is loaded
if (!$model->getId()) {
Mage::getSingleton('adminhtml/session')->addError($this->__('This Contact Request no longer exists.'));
$this->_redirect('*/*/');
return;
}
}
$this->_title($model->getId() ? $model->getName() : $this->__('New Contact Request'));
$data = Mage::getSingleton('adminhtml/session')->getContactRequestData(true);
if (!empty($data)) {
$model->setData($data);
}
Mage::register('whatever_booking', $model);
$this->_addBreadcrumb($id ? $this->__('Edit Contact Request') : $this->__('New Contact Request'), $id ? $this->__('Edit Contact Request') : $this->__('New Contact Request'));
$block = $this->getLayout()->createBlock('whatever_booking/adminhtml_contactRequest_edit')->setData('action', $this->getUrl('*/*/save'));
$this->getLayout()->getBlock('content')->append($block);
$this->renderLayout();
}
protected function _initAction()
{
$this->loadLayout()
->_setActiveMenu('customer/ContactRequest')
->_title($this->__('Whatever Booking'))->_title($this->__('Contact Request'));
return $this;
}
我的形式:
class Whatever_Booking_Block_Adminhtml_ContactRequest_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
/**
* Init class
*/
public function _construct()
{
parent::_construct();
$this->setId('whatever_booking_contactRequest_form');
$this->setTitle($this->__('Contact Request Information'));
//when i var dump here i see that my controller called this function
}
protected function _prepareForm()
{
var_dump('here');
die; // this var dump is never reached
}
}
編輯塊
class Whatever_Booking_Block_Adminhtml_ContactRequest_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
{
/**
* Init class
*/
public function _construct()
{
$this->_blockGroup = 'whatever_booking';
$this->_controller = 'adminhtml_contactRequest';
parent::_construct();
$this->_updateButton('save', 'label', $this->__('Save Request'));
$this->_updateButton('delete', 'label', $this->__('Delete Request'));
}
/**
* Get Header text
*
* @return string
*/
public function getHeaderText()
{
if (Mage::registry('contact_request')->getId()) {
return $this->__('Edit Request');
}
else {
return $this->__('New Request');
}
}
protected function _prepareLayout()
{
// mage log is passing here when i display one
return parent::_prepareLayout();
}
你的控制器,似乎打電話錯過被$ this-> loadlayout(),是在_initaction()? – Mir
我編輯了我的_initAction文章,是的它被稱爲那裏,所以它不是問題:) –