How to add new admin menu items without reinstalling component in joomla?

Umut KIRGÖZ picture Umut KIRGÖZ · Jan 4, 2012 · Viewed 9.6k times · Source

I have been developing a component for Joomla 1.7.x, during development I need to add new component menu items to admin menu, it was easy by adding new rows to components table in DB in Joomla 1.5 times, but now it seems complicated to add a menu item by adding new row to menu table because of the database structure changes in Joomla 1.7

Is there a easy way to do this without reinstalling the component?

tHanks

Answer

admit picture admit · Oct 28, 2012

The easiest way I found:

$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;
}

To delete:

$table->delete(120); // item ID
$table->rebuild();

Based on http://docs.joomla.org/Using_nested_sets#Adding_a_new_node