[英]Create an admin menu in Opencart 4
In Opencart4 I am creating a new module.在 Opencart4 中,我正在创建一个新模块。 Installed the module and working fine from accessing
Admin-> extensions -> modules -> module name -> (then edit)
.安装了模块并通过访问
Admin-> extensions -> modules -> module name -> (then edit)
正常工作。
Now I would like to add a new menu item under the "Catalogue" menu in the admin part.现在我想在管理部分的“目录”菜单下添加一个新菜单项。
I have done the following我做了以下
In module's controller I added在模块的 controller 我添加
$this->load->model('setting/event');
$this->model_setting_event->deleteEventByCode('MY_EVENT');
$this->model_setting_event->addEvent('MY_EVENT', "",'admin/view/common/column_left/before', 'extension/testimonials/module/testimonials/ADDTOADMINMENU');
ADDTOADMINMENU
function in the module's controller looks like ADDTOADMINMENU
function 在模块的 controller 看起来像
public function ADDTOADMINMENU(&$route, &$data){
/**
* Check if current logged in user has permission to access that link
* Replace "extension/module/MY_EXTENSION" with your target path
* This check can very well be ignored/deleted...
**/
echo "Here";
exit;
if ($this->user->hasPermission('access', 'extension/testimonials/module/testimonials')) {
$my_menu_entry = array(
'id' => 'menu-MY_EXTENSION',
'icon' => 'fa-check',
'name' => 'My menu entry',
'href' => $this->url->link('extension/testimonials/module/testimonials', 'user_token=' . $this->session->data['user_token'], true),
'children' => array()
);
$target_menu_id = 'menu-catalog';
$target_submenu_href = $this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'], true);
$new_menu = array();
foreach( $data['menus'] as &$menu ) {
if( $menu['id'] == $target_menu_id ) {
$new_submenu = array();
foreach( $menu['children'] as $submenu ) {
if( $submenu['href'] == $target_submenu_href ) {
$new_submenu[] = $my_menu_entry;
$new_submenu[] = $submenu;
} else {
$new_submenu[] = $submenu;
}
}
$menu['children'] = $new_submenu;
$new_menu[] = $menu;
} else {
$new_menu[] = $menu;
}
}
$data['menus'] = $new_menu;
}
}
But not even entering in this function.但甚至没有进入这个function。 Is the correct way I am following?
我遵循的正确方法是什么?
Please guide.请指导。
try this:尝试这个:
$this->model_setting_event->addEvent('MY_EVENT', "",'admin/view/common/column_left/before', 'extension/testimonials/module/testimonials/ADDTOADMINMENU');
replace with:用。。。来代替:
$this->model_setting_event->addEvent('MY_EVENT', "",'admin/view/common/column_left/before', 'extension/testimonials/module/testimonials|ADDTOADMINMENU');
I have not checked, but OC have changed they framework a bit.我没有检查过,但是 OC 已经稍微改变了它们的框架。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.