I am writing my extension on Joomla and I need to create a new menu item at some point in the expansion. What is the best way to do this?

  • What does "extension work at a certain point" mean? Tell me more about what you want to do - Arsen
  • We have an extension on Jumla. Suppose in Joomla there is a menu with three items (each menu item is a link to the article). The extension should create a fourth menu item with the specified article. Interests what system calls are for this purpose necessary. - progreccor
  • Ie you want to automatically create a menu? - Arsen
  • Yes, absolutely true. The extension I create should be able to create a menu item myself. - progreccor

1 answer 1

In order to add a menu to Joomla in your component, you need to use the Joomla Menu Model , for example:

 <?php $menuTable = JTableNested::getInstance('Menu'); $menuData = array( 'menutype' => 'Ρ‚ΠΈΠΏ_вашСго_мСню', /* Π’ΠΈΠΏ мСню Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±Ρ‹Ρ‚ΡŒ Π»Π°Ρ‚ΠΈΠ½ΠΈΡ†Π΅ΠΉ ΠΈ Π±Ρ‹Ρ‚ΡŒ ΡƒΠ½ΠΈΠΊΠ°Π»ΡŒΠ½Ρ‹ΠΌ*/ 'title' => 'НазваниС мСню', 'alias' => 'Алиас мСню', 'url' => 'URL menu', /* URL мСню Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ :index.php?com_yourcomponent&...... */ 'path' => 'Seo URL', /* Seo URL мСню Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€: path/component_path/last_item/ */ 'type' => 'component', /* Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½ΠΈΠΉ Ρ‚ΠΈΠΏ мСню*/ 'component_id' => 0, /* ID ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° Π² #__extensions */ 'language' => '*', 'published' => 1, ); $parent_id = 1; /* Ссли это Π΄ΠΎΡ‡Π΅Ρ€Π½Π΅Π΅ мСню, Ρ‚ΡƒΡ‚ прописываСтся ID родитСля */ $menuTable->setLocation($parent_id, 'last-child'); if (!$menuTable->save($menuData)) { $this->setError($menuTable->getError()); return false; } ?>