[TYPO3-ect] lib/div: some common initialization before any action
Elmar HInz
elmar.hinz at team.MINUS.red.DOT.net
Fri Mar 23 22:07:02 CET 2007
Am Fri, 23 Mar 2007 21:26:46 +0300 schrieb Alexey Boriskin:
> I am writing an extension based on lib/div framework. It's a pleasure :)
> But I have a feature request.
> I need to create some commonly used objects, for example, object that
> manage user rights which should be accessible in any action of my
> conroller. I cannot extend constuctor of controller because my 'rights'
> object want to use configurations sub-object of a controller, but it is
> not yet created.
>
Hello Alexey,
thank you for joining ECT.
I will think about an init function. But I am a little frightend that
people will be tempted to leave the path of object orientation.
Why is it not possible to extend the constructor/main function?
I would try to do it this way, by overwriting the main function in the
inherited class:
class tx_apples_controllers_example extends tx_lib_controller{
function main($out, $configurationArray){
// Making the configurations object
$configurations = $this->_makeConfigurationsObject($configurationArray);
// Making the parameters object
$parameters = $this->_makeParameterObject();
// Finding the action:
$action = $this->_findAction($parameters, $configurations);
// Finding the controller for the action
$controllerName = $this->_findController($this->getClassName(), $action);
// If we didn't find a controller for it, the action is not known
if(!$controllerName){
$controllerName = $this->getClassName();
$action = 'unknownAction';
}
// Creating the ultimative controller instance (may be an instance of the same class)
$controller = tx_div::makeInstance($controllerName);
$controller->parameters = $parameters;
$controller->configurations = $configurations;
//----------------------------------------------------
// Your change here:
//----------------------------------------------------
$controller->init();
//----------------------------------------------------
return $controller->$action();
}
function init(){ ... }
function exampleAction() {
$modelClassName = tx_div::makeInstanceClassName('tx_apples_models_example');
$viewClassName = tx_div::makeInstanceClassName('tx_apples_views_example');
$view = new $viewClassName(new $modelClassName());
$view->setController($this);
$view->setTemplatePath($this->getConfiguration('templatePath'));
return $view->render($this->getConfiguration('exampleTemplate'));
}
}
There are also some alternative ways. Just some hints:
a) Make a rights object all in analogy to the parameters and the
configurations object and access it in analogous way. Maybe the most
perfect solution.
b) Make the rights management part of an extended configuration object.
c) Have a common action part, that you call from every other action first.
Regards
Elmar
More information about the TYPO3-team-extension-coordination
mailing list