Magento 自定义模块 - 如何添加带有父类别的自定义选择框
我编写了一个模块来拥有自己的菜单栏,而不是仅仅使用类别作为菜单栏。
因此,在这里我想显示已添加的菜单,同时在自定义菜单模块的 Tab/Form.php 中添加新菜单。如何在表单上将所有现有菜单名称显示为下拉列表/选项列表。这是我用来制作菜单表单的代码。
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('menu_form', array('legend'=>Mage::helper('menu')->__('Menu information')));
$note = "Name of this Menu";
$fieldset->addField('title', 'text', array(
'label' => Mage::helper('menu')->__('Menu Name'),
'class' => 'required-entry',
'required' => true,
'note' => $note,
'name' => 'title',
));
$note = "Menu level";
$fieldset->addField('level', 'select', array(
'label' => Mage::helper('menu')->__('Menu level'),
'name' => 'level',
'note' => $note,
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('menu')->__('Level 1'),
),
array(
'value' => 2,
'label' => Mage::helper('menu')->__('Level 2'),
),
),
));
$model = Mage::registry('menu');
$fieldset->addField('parent', 'text', array(
'name' => 'conditions',
'label' => Mage::helper('menu')->__('Parent Menu'),
'title' => Mage::helper('menu')->__('Parent Menu'),
'required' => false,
'note' => $note,
))->setRule($model)->setRenderer(Mage::getBlockSingleton('rule/conditions'));
$fieldset->addField('target', 'select', array(
'label' => Mage::helper('menu')->__('Open in new window'),
'name' => 'target',
'values' => array(
array(
'value' => "_blank",
'label' => Mage::helper('menu')->__('Yes'),
),
array(
'value' => "_self",
'label' => Mage::helper('menu')->__('No'),
),
),
));
$fieldset->addField('status', 'select', array(
'label' => Mage::helper('menu')->__('Status'),
'name' => 'status',
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('menu')->__('Enabled'),
),
array(
'value' => 2,
'label' => Mage::helper('menu')->__('Disabled'),
),
),
));
$note = "Menu Links to Which page. BaseURL(<b>".str_ireplace("index.php/","",Mage::getBaseUrl())."</b>) Will be Added Dynamically, Please add Your new page Refrence alone";
$fieldset->addField('menulink', 'text', array(
'label' => Mage::helper('menu')->__('URL'),
'required' => true,
'class' => 'required-entry',
'note' => $note,
'name' => 'menulink',
));
$fieldset->addField('position', 'select', array(
'label' => Mage::helper('menu')->__('Position'),
'name' => 'position',
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('menu')->__('Top 1'),
),
array(
'value' => 2,
'label' => Mage::helper('menu')->__('Top 2'),
),
),
));
if ( Mage::getSingleton('adminhtml/session')->getMenuData() )
{
$form->setValues(Mage::getSingleton('adminhtml/session')->getMenuData());
Mage::getSingleton('adminhtml/session')->setMenuData(null);
} elseif ( Mage::registry('menu_data') ) {
$form->setValues(Mage::registry('menu_data')->getData());
}
return parent::_prepareForm();
在此我想显示父菜单选项下所有添加的菜单。我应该在我的模型类中编写什么,以便我可以有一个下拉列表来显示所有它们,并且添加后应该将其添加到数据库中。
请帮助我,我在这里挣扎。
I wrote a module to have my own menu bar, rather than just using categories as a menu bar.
So, here I want to show already added menus while adding new menu in the Tab/Form.php in my custom menu module. How can I show all of the existing menu names as a dropdown/options list on the form. Here is the code that I used to have menu form.
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('menu_form', array('legend'=>Mage::helper('menu')->__('Menu information')));
$note = "Name of this Menu";
$fieldset->addField('title', 'text', array(
'label' => Mage::helper('menu')->__('Menu Name'),
'class' => 'required-entry',
'required' => true,
'note' => $note,
'name' => 'title',
));
$note = "Menu level";
$fieldset->addField('level', 'select', array(
'label' => Mage::helper('menu')->__('Menu level'),
'name' => 'level',
'note' => $note,
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('menu')->__('Level 1'),
),
array(
'value' => 2,
'label' => Mage::helper('menu')->__('Level 2'),
),
),
));
$model = Mage::registry('menu');
$fieldset->addField('parent', 'text', array(
'name' => 'conditions',
'label' => Mage::helper('menu')->__('Parent Menu'),
'title' => Mage::helper('menu')->__('Parent Menu'),
'required' => false,
'note' => $note,
))->setRule($model)->setRenderer(Mage::getBlockSingleton('rule/conditions'));
$fieldset->addField('target', 'select', array(
'label' => Mage::helper('menu')->__('Open in new window'),
'name' => 'target',
'values' => array(
array(
'value' => "_blank",
'label' => Mage::helper('menu')->__('Yes'),
),
array(
'value' => "_self",
'label' => Mage::helper('menu')->__('No'),
),
),
));
$fieldset->addField('status', 'select', array(
'label' => Mage::helper('menu')->__('Status'),
'name' => 'status',
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('menu')->__('Enabled'),
),
array(
'value' => 2,
'label' => Mage::helper('menu')->__('Disabled'),
),
),
));
$note = "Menu Links to Which page. BaseURL(<b>".str_ireplace("index.php/","",Mage::getBaseUrl())."</b>) Will be Added Dynamically, Please add Your new page Refrence alone";
$fieldset->addField('menulink', 'text', array(
'label' => Mage::helper('menu')->__('URL'),
'required' => true,
'class' => 'required-entry',
'note' => $note,
'name' => 'menulink',
));
$fieldset->addField('position', 'select', array(
'label' => Mage::helper('menu')->__('Position'),
'name' => 'position',
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('menu')->__('Top 1'),
),
array(
'value' => 2,
'label' => Mage::helper('menu')->__('Top 2'),
),
),
));
if ( Mage::getSingleton('adminhtml/session')->getMenuData() )
{
$form->setValues(Mage::getSingleton('adminhtml/session')->getMenuData());
Mage::getSingleton('adminhtml/session')->setMenuData(null);
} elseif ( Mage::registry('menu_data') ) {
$form->setValues(Mage::registry('menu_data')->getData());
}
return parent::_prepareForm();
In this I want to show all the added menus under the parent menu option. What should I write in my Model class so that I can have a drop down list to show them all, and after adding it should be added to database.
Please help me, am struggling here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过添加这些行来完成此操作。
它将显示已添加的菜单作为下拉列表,以便您可以选择其中任何一个作为当前项目的父菜单。
You can do this by adding these lines.
It will show already added menus as a dropdown list so that you can choose any of them as a parent menu for current item.