我正在创建一个模块,允许用户在创建角色权限期间选择网站(系统 -> 权限 -> 角色 -> 添加新角色 -> 角色资源)。我正在使用观察者来实现这一点,但是我无法获得表单对象。
观察者.php
class Mymodule_Mycompany_Model_Observer
{
public function appendCustomRow(Varien_Event_Observer $observer)
{
$block = $observer->getEvent()->getBlock();
if (!isset($block)) {
return $this;
}
if ($block->getType() == 'adminhtml/permissions_editroles') {
//get form instance
$form = $observer->getEvent()->getForm();
//create new custom fieldset 'website'
$fieldset = $form->addFieldset('website', array(
'legend' => 'Website Extras',
'class' => 'fieldset-wide'
)
);
//add new field
$fieldset->addField('website', 'text', array(
'name' => 'website',
'label' => Mage::helper('adminhtml')->__('Website'),
'title' => Mage::helper('adminhtml')->__('Website'),
'disabled' => false,
));
}
}
}
我的模块/我的公司/etc/config.xml
<adminhtml>
<events>
<core_block_abstract_prepare_layout_before>
<observers>
<Event_column_append>
<type>model</type>
<class>Mymodule_Mycompany_Model_Observer</class>
<method>appendCustomColumn</method>
</Event_column_append>
</observers>
</core_block_abstract_prepare_layout_before>
</events>
</adminhtml>