J2.5 talk

Creating a System Plugin to augment JRouter

From Joomla! Documentation

Revision as of 08:13, 15 July 2013 by Wilsonge (talk | contribs) (Wilsonge moved page Talk:Creating a System Plugin to augment JRouter to J2.5 talk:Creating a System Plugin to augment JRouter: Move into J2.5 namespace)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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)



Thanks....updated. At the end of the day there should be one 'someplace' to get default system objects. It doesn't really matter to me which one it is...as long as it is maintained for backwards compatibility. Some of the getInstance functions haven't been, so I always debate internally whether I want to count on the api....or an existing known variable.



Whilst I was testing this I saw that the callbacks added with $router->attachBuildRule have their return values are discarded. Callbacks added with $router->attachParseRule have their return $var's used. tracesOfNut (talk) 04:29, 26 September 2012 (CDT)