The file, site/helloworld.php, is the main entry point file for Joomla component. The main entry point passes control to the controller, which handles performing the task that was specified in the request.
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// Get an instance of the controller prefixed by HelloWorld
$controller = JControllerLegacy::getInstance('HelloWorld');
// Perform the Request task
$input = JFactory::getApplication()->input;
// Redirect if set by the controller
The first line enables for a secure entry point into the Joomla platform.
JControllerLegacy is a base class for a Joomla Controller. In order to use controllers, you must extend this class in your component. The getInstance static method of the JControllerLegacy class will create a controller. In the code above, it will instantiate a controller object of a class named HelloWorldController.
Joomla will look for the declaration of that class in /components/com_helloworld/controller.php.
After the controller is created, the controller executes the task, as defined in the URL:
If no task is set, the default task 'display' will be assumed. When display is used, the 'view' variable will decide what will be displayed.
Other common tasks are save, edit, new, and so on.
The controller might decide to redirect the page, usually after a task like 'save' has been completed. This last statement takes care of the actual redirection.