[TYPO3-mvc] How should/can I pass parameters to an object's constructor using dependency injection?
Bastian Waidelich
bastian at typo3.org
Thu Nov 18 17:22:35 CET 2010
Simon Tuck wrote:
Hi Simon
> I'm looking at the changes in the latest version of extbase (1.3) and I
> was wondering how I would/could pass parameters to an object's
> constructor using the DI container.
> /**
> *
> * @param string $foo
> * @return void
> */
> public function __construct($foo)
> {
> $this->setFoo($foo);
> }
Just like that ;)
But you can't inject simple types (string, integer, boolean, ...)
because.. How should the DI container know what value to inject?
This works:
/**
* @param Tx_YourExt_SomeClass $someObject
*/
public function __construct(Tx_YourExt_SomeClass $someObject) {
$this->setSomeObject($someObject);
}
Don't forget to hit the "clear all caches" button in the BE in order to
tell the DI framework to recreate the object caches.
HTH
Bastian
More information about the TYPO3-project-typo3v4mvc
mailing list