Auto redirect guests to login

From Joomla! Documentation

Revision as of 01:33, 15 April 2009 by EivindJ (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

I'm developing a component that I want to be visible to all but force the user to log in before using it. I am using the following code in the default php file that my component runs upon loading.

$user = & JFactory::getUser();

 if ($user->guest)
   $forceLoginController = new JController;

I'm pretty much a Joomla! noob, but I don't see any reason why this shouldn't be used.