简体   繁体   English

在Joomla 2.5中使用组件的多个视图中的一个菜单

[英]Using one menu in multiple views of a component in Joomla 2.5

I wrote a component in Joomla 2.5 and I use this 我在Joomla 2.5中编写了一个组件,我使用它

JSubMenuHelper::addEntry('Alpha', 'index.php?option=com_teams&task=showA');
JSubMenuHelper::addEntry('Beta', 'index.php?option=com_teams&task=showB',true);
JSubMenuHelper::addEntry('Gamma', 'index.php?option=com_teams&task=showC');
...

in each of the view.html.php files to switch from on view to another. 在每个view.html.php文件中从视图切换到另一个。

This works fine, but it is annoying if I add or change a menu item, because I have to change it in all the files individually. 这工作正常,但如果我添加或更改菜单项,这很烦人,因为我必须单独更改所有文件。

What is the best (and conform to MVC design) way to accomplish that? 什么是最好的(并符合MVC设计)方法来实现这一目标? I guess just simply use the php methods (include or require) isn't the way to go. 我想只是简单地使用php方法(包含或要求)不是要走的路。

Instead of calling that in each of the view.html.php files, I usually call that specific code, in controller.php or controllers/*.php, so that it is kind of a "global" code for my components. 我通常在controller.php或controllers / * .php中调用该特定代码,而不是在每个view.html.php文件中调用它,这样它就是我的组件的“全局”代码。

I'm not 100% sure if it is the best way to do it in MVC, but as in some comments above, you can also use helper functions to call that code, and avoid maintaining it in multiple points. 我不是100%确定它是否是在MVC中执行此操作的最佳方式,但正如上面的一些注释中,您还可以使用辅助函数来调用该代码,并避免将其保留在多个点中。

Although, I am pretty sure that I have found this instruction (calling in the controller) in some Joomla! 虽然,我很确定我在一些Joomla中找到了这条指令(在控制器中调用)! tutorial, or in another Joomla! 教程,或另一个Joomla! component, so it's generally a good practice so far. 组件,所以到目前为止通常是一个很好的做法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM