我一直在为 Joomla 1.7.x 开发一个组件,在开发过程中我需要向管理菜单添加新的组件菜单项,通过在 Joomla 1.5 次中向 DB 中的组件表添加新行很容易,但现在添加似乎很复杂由于 Joomla 1.7 中数据库结构的变化,通过向菜单表添加新行的菜单项
有没有一种简单的方法可以在不重新安装组件的情况下做到这一点?
谢谢
最佳答案
我发现的最简单的方法:
$table = JTable::getInstance('menu');
$data = array();
$data['menutype'] = 'main';
$data['client_id'] = 1;
$data['title'] = 'ITEM TITLE';
$data['alias'] = 'com-component-name';
$data['link'] = 'index.php?option=com_component_name&view=default';
$data['type'] = 'component';
$data['published'] = '0';
$data['parent_id'] = '117'; // ID, under which you want to add an item
$data['component_id'] = '10026'; // ID of the component
$data['img'] = 'components/com_component_name/assets/images/icon.png';
$data['home'] = 0;
if (
!$table->setLocation(117, 'last-child') // Parent ID, Position of an item
|| !$table->bind($data)
|| !$table->check()
|| !$table->store()
){
// Install failed, warn user and rollback changes
JError::raiseWarning(1, $table->getError());
return false;
}
删除:
$table->delete(120); // item ID
$table->rebuild();
基于 http://docs.joomla.org/Using_nested_sets#Adding_a_new_node
关于menu - 如何在不重新安装 joomla 组件的情况下添加新的管理菜单项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8733833/