SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 108 | Next

James Kennard

"Mastering Joomla! 1.5 Extension and Framework Development"

This example defines a controller called MyextensionController:
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted Access');
jimport('joomla.application.component.controller');
/**
* MyExtension Controller
*
*/
class MyextensionController extends JController
{ }
There are many methods within the JController class, which we can override. The
most commonly overridden method is display(). This method instantiates a view
object, attaches a model to the view and initiates the view.
There are two important request variables, which are used by the display() method
to determine what it does. The view request determines which view to instantiate.
The layout argument determines which layout to use if the document type is HTML.
Component Design
[ 80 ]
This might sound as if it does everything we need. However, there is a common
reason for overloading the display() method. We might want to increment a hit
counter associated with an entity. In this example, we do just that:
/**
* MyExtension Controller
*
*/
class MyextensionController extends JController
{
/**
* Display
*
*/
function display()
{
// get the Foobar model and increment the counter
$modelFoobar =& $this->getModel('Foobar');
$modelFoobar->hit();
// display foobar
parent::display();
}
}
Note that to obtain the MyextensionModelFoobar object we use the
getModel() method and supply it with the name of the model.


Pages:
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120