Answer the question
In order to leave comments, you need to log in
How to display a component's menu on all page views?
I am writing a Joomla component called Ypay for myself. The file structure is as in the screenshot https://i.stack.imgur.com/B098N.png. And here is a screenshot of the menu itself https://i.stack.imgur.com/2UiC2.png Each menu item will have its own model and its own views. But how to display this menu on all views?
код меню в models/ypay.php
class YPayModelYPay extends JModelItem
{
protected $messages;
protected function getMenuFromDb()
{
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('menu_name, parent_menu_name, has_child_menu');
$query->from('#__ypay_mainmenu');
$db->setQuery((string) $query);
$messages = $db->loadAssocList();
return $messages;
}
public function getMenuNameMsg()
{
if (!isset($this->message))
{
$this->message = $this->getMenuFromDb();
}
return $this->message;
}
}
код меню в views/ypay.html.php
class YPayViewYPay extends JViewLegacy
{
function display($tpl = null)
{
// Assign data to the view
$this->msg = $this->get('MenuNameMsg');
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JLog::add(implode('<br />', $errors), JLog::WARNING, 'jerror');
return false;
}
$this->showMainMenu();
// Display the view
parent::display($tpl);
}
public function showMainMenu()
{
foreach ($this->msg as $item => $value) {
if ($value['has_child_menu'] == '0' && $value['parent_menu_name'] ==
'0') {
echo "<a href=''><input type='button' style='padding-bottom:
5px;' class='btn btn-primary btn-ypay' id='projects-btn' value=" .
$value['menu_name'] . "></a>";
} elseif ($value['has_child_menu'] == '1') {
$liItem = [];
$parentMenu = $value['menu_name'];
echo '<div class="dropdown" style="display: inline; margin-
right: 5px;"><button class="btn btn-primary dropdown-toggle" type="button"
data-toggle="dropdown">' . $value['menu_name'] .' '. '<span class="caret">
</span></button><ul class="dropdown-menu">';
foreach ($this->msg as $key => $data) {
if ($parentMenu == $data['parent_menu_name']) {
$liItem[] = $data['menu_name'];
}
}
for ($i = 0; $i <= count($liItem) - 1; $i++) {
echo '<li><a href="/ypay/index.php?
option=com_ypay&view=workers">' . $liItem[$i] . '</a></li>';
if ($liItem[$i] !== $liItem[count($liItem) - 1]) echo '<li
class="divider" style="border-bottom: 1px solid #007bcc; margin: 2px 1px 2px
2px;"></li>';
}
echo '</ul></div>';
unset($liItem);
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question