Home API Docs Linkr Putting it all together Hello World - Component

Hello World - Component

Attention: open in a new window.PDFPrintEmail
Article Index
Hello World
Component
Plugin
All Pages

Part 1: The component

For documentation on building a Joomla! component, follow this link External link.

For this example, the component will follow the MVC design. Since this extension does nothing else outside Linkr, it will have one controller. Moreover, the only task for the controller will be to display the translated text. So, no view is needed here. The controller needs to be able to send text over an AJAX request. Here's one way to do it:
// Hello Linkr controller
class Hello_linkrController extends JController
{
  function display()
  {
    // Get model
    $hello = & $this->getModel( 'hello' );
 
    // Get the language we're translating into
    $lang = JRequest::getVar( 'lang', 'hr' );
 
    // Get translation
    $trans = $hello->getTranslation( $lang );
 
    // Since this is an AJAX request,
    // we don't need a view to display the result.
    // In this example, we will simply echo it
    // and shutdown the Joomla! application.
    echo $trans;
 
    // Quit Joomla!
    global $mainframe;
    $mainframe->close();
  }
}
This can be done in a number of ways, and you should find the one that fits best into your extension.


Linkr 2.3.7 (20 May 2010) is finally out. This release tackles many bugs and will make the overall usage a little smoother.