How to invoke Menu rebuild from the custom front-end component in Joomla?
Asked Answered
A

1

6

I am using Joomla 2.5 to create a special component that is executed from the front-end.

This component parses xml file to build Joomla menu, I'm executing INSERT INTO #__menu query, but I leave 0s for lft and rgt fields.

The menu is being built very messy, and when I click Rebuild button at the back-end everything looks perfect after that, path, lft, and rgt fields are being correctly filled.

I have spent 2 days trying to execute rebuild task from my front-end component's controller and module, I've even tried to use jimport('joomla.database.tablenested') but my lack of PHP OOP knowledge doesn't help me to correctly execute rebuild function...

The last thing I wrote was this:

jimport('joomla.database.tablenested');
class BSImportModelBSImport extends JModel
{
  ...
  function theimport()
  {
    ...
    $db =& JFactory::getDBO();
    $menu = new JTableNested('Menu', 'id',&$db);
    return $menu->rebuild();
  }
}

Please don't throw stones to my head if my question looks stupid... I really need help...

Argentic answered 26/3, 2012 at 4:45 Comment(2)
Holy StackOverflow! Thank you Thank you Thank you! I apologize for giving up so fast when the answer was so close... Of course!!! I just needed to replace: $menu = new JTableNested('Menu', 'id',&$db); with $menu = new JTableNested('#__menu', 'id',&$db); I hope this will help somebody... I apologize to moderators for my mistake again... Thank you!Argentic
you should post a response and accept it to close this question...Delanty
R
1

I use save method of menu table:

$data = array ( 
    'id' => 0 ,
    'title' => '{menu name}' ,
    'note' => '',
    'link' => '{link}',
    'menutype' => '{menutype}' ,
    'type' => 'url', 
    'published' => 1 ,
    'parent_id' => 1 ,
    'level' => 1 ,
    'component_id' => 0 ,
    'browserNav' => 0 ,
    'access' => getLevel() ,
    'template_style_id' => 0 ,
    'language' => '*' ,
    'params' => array ( 
        'menu-anchor_title' => '' ,
        'menu-anchor_css' => '' ,
        'menu_image' => '{url of logo for menu}',
        'menu_text' => 1 ) ,
);
$menuTable = JTable::getInstance('Menu', 'JTable', array());
$menuTable->save($data);

This method create new menu and rebuild automatically.

Retainer answered 4/5, 2013 at 7:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.