我已经想好了如何将实际的选项卡项添加到我的自定义模块中,但我无法像系统模块那样添加绿色的部分标题。使用system.xml文件将自己的模块添加到系统模块本身并不困难,但是如何将其添加到自己的模块菜单中呢?!
edit:添加了我用于选项卡的代码作为参考。正在扩展的区块的文档也发布在下面。http://docs.magentocommerce.com/Mage_Adminhtml/Mage_Adminhtml_Block_Widget_Tabs.html
这是为了添加选项卡,但它们的部分标题呢??
$this->addTab('custom_assigned_tab1_id_name', array(
'label' => Mage::helper('coffefreakhelper1')->__('Custom tab1 here'),
'title' => Mage::helper('coffefreakhelper1')->__('My custom tab1 title here'),
'content' => 'Some content here. We could add direct string here, or we can use something like $this->getLayout()->createBlock("adminhtml/cms_page_edit_tab_main")->toHtml()',
'active' => true
));
编辑:解决了
在查看了System块之后,我注意到他们制作了一个特定的模板和一些实用方法来处理小部件类。因此,知道了这一点,我扩展了Mage_Adminhtml_Block_System_Config_Tabs,而不是Mage_Adminhtml_Block_Widget类。下面我有一个测试的例子。
class Inchoo_CoffeeFreak_Block_ShowTabsAdminBlock extends Mage_Adminhtml_Block_System_Config_Tabs {
protected $_tabs;
public function __construct() {
parent::__construct();
$this -> setId('test_config_tabs');
$this -> setTitle("Test Tab Page");
$this -> setTemplate('system/config/tabs.phtml');
}
protected function _beforeToHtml() {
for($tab = 1; $tab < 4; $tab++){
$tabCode = 'tab_' . $tab;
$tabTitle = "Tab " . $tab;
$this -> addTab($tabCode, array("label" => $tabTitle, "class" => ""));
for($section = 1; $section < 4; $section++){
$sectionCode = "section_" . $tab . "_" . $section;
$sectionTitle = "Section " . $section;
$this -> addSection($sectionCode, $tabCode, array('class' => '', 'label' => $sectionTitle, 'url' => '', ));
}
}
$this -> setLastSections();
return parent::_beforeToHtml();
}
public function setLastSections() {
foreach ($this->getTabs() as $tab) {
$sections = $tab -> getSections();
if ($sections) {
$sections -> getLastItem() -> setIsLast(true);
}
}
}
}
结果如下图所示。
https://drive.google.com/file/d/0By8e425vlQRuNFBxSjRuM3NKTnc/view?usp=sharing
我扩展的类引用了"选项卡"作为主要部分的标题。它将每个分组的子选项卡分隔开。子选项卡称为"节"。我的测试脚本只是循环并创建3个选项卡,每个选项卡有3个部分。
我在我的主帖子中添加了一个带有答案的编辑。为其他想使用它的人提供了一个测试片段。
同样值得一提的是,我的样板模块是由Inchoo创建的,可以在下面的链接中查看。我用上面粘贴的代码替换了他们的标签代码。结果是一个很好的菜单,有一个标题的分组选项卡。
http://inchoo.net/magento/coffeefreak-blank-magento-extension-for-building-main-admin-menu-with-sidebar-and-tabs/