Creating a System Plugin to augment JRouter: Difference between revisions
From Joomla! Documentation
m moved Talk:Using a System Plugin to augment JRouter to Talk:Creating a System Plugin to augment JRouter: following current standard |
No edit summary |
||
| Line 8: | Line 8: | ||
Which is the preferred option? | Which is the preferred option? | ||
---- | |||
Use of '''global''' is a smell of bad code. It will import any variable from the global name space identified by its name, regardless of its meaning. In an ideal world the global namespace would not be polluted with global variables. So the latter option is the (only) right one. | |||
[[User:Nibra|Nibra]] 13:53, 10 April 2012 (CDT) | |||
Revision as of 18:53, 10 April 2012
From within a plugin, there are 2 ways to get the currently active application context. One is to use the global $app variable:
global $app;
The other is to use JFactory to get the application.
$app = JFactory::getApplication('site');
Which is the preferred option?
Use of global is a smell of bad code. It will import any variable from the global name space identified by its name, regardless of its meaning. In an ideal world the global namespace would not be polluted with global variables. So the latter option is the (only) right one.
Nibra 13:53, 10 April 2012 (CDT)