[TYPO3-ect] lib/div: some common initialization before any action
Ernesto Baschny [cron IT]
ernst at cron-it.de
Mon Mar 26 10:46:22 CEST 2007
Alexey Boriskin wrote: on 23.03.2007 19:26:
> 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.
>
> So, my proposal is to define a method of tx_lib_controller, that should
> be called before any action.
>
> @@ -191,9 +191,17 @@
> $controller = tx_div::makeInstance($controllerName);
> $controller->parameters = $parameters;
> $controller->configurations = $configurations;
> + $controller->init();
> return $controller->$action();
> }
Elmar, the problem with the full "object orientation" is not possible
with "t3lib_div::makeInstance", since you cannot pass the newly created
object any parameters. This is why you sometimes need some kind of
"post-constructor" so that you can process parameters needed for proper
initiation of your new object. Stuff like:
$controller->parameters = $parameters;
$controller->configurations = $configurations;
to me are candidates for passing to the constructor.
It would be nice to separate the creation of the object from its later
use (main()). Having a init() after setting every needed stuff seems to
be a pragmatic way of doing that, while keeping the current
makeInstance() usage.
Cheers,
Ernesto
More information about the TYPO3-team-extension-coordination
mailing list