Я пытаюсь создать реальную сетку на основе модели magento. Все работает хорошо на прочитанной части, но форма для редактирования не отображается, и у меня нет ошибок в журналах. Я заметил, что моя функция _prepareForm никогда не вызывается, но я не знаю почему.Magento Form Block not rendered
Моя форма вызова в контроллере:
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, и да, он называется там, поэтому это не проблема :) –