DS.'controller.php');
Component Design
[ 84 ]
// get controller
if ($c = JRequest::getCmd('c', 'DefaultEntity'))
{
// determine path
$path = JPATH_COMPONENT.DS.'controllers'.DS.$c.'.php';
jimport('joomla.filesystem.file');
if (JFile::exists($path))
{
// controller exists, get it!
require_once($path);
}
else
{
// controller does not exist
JError::raiseError('500', JText::_('Unknown controller'));
}
}
// instantiate and execute the controller
$c = 'MyextensionController'.$c;
$controller = new $c();
$controller->execute(JRequest::getCmd('task', 'display'));
// redirect
$controller->redirect();
An alternative method is to encapsulate this within another layer of inheritance. For
example we could create the controller class MyextensionController and add a
getInstance() method to it that will return an object of the desired subclass. This
example demonstrates how we might implement such a method:
/**
* Gets a reference to a subclass of the controller.
*
* @static
* @param string entity name
* @param string controller prefix
* @return MyextensionController extension controller
*/
function &getInstance($entity, $prefix='MyExtensionController')
{
// use a static array to store controller instances
static $instances;
if (!$instances)
{
$instances = array();
}
// determine subclass name
$class = $prefix.
Pages:
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127