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