Closed FiMka closed 9 years ago
It is interesting if I change the controller to:
class PartOfSpeechController extends AbstractRestfulController {
...
public $partOfSpeechService;
public function __construct(PartOfSpeechService $partOfSpeechService) {
return $this->partOfSpeechService = $partOfSpeechService;
}
public function processPostData(Request $request) {
$partsOfSpeech = $this->partOfSpeechService->getPartsOfSpeech("test", "en_EN");
return new JsonModel($partsOfSpeech);
}
I get:
PHP Catchable fatal error: Argument 1 passed to
Morpho\Controller\PartOfSpeechController::__construct()
must be an instance of
Morpho\Service\PartOfSpeechService, none given, called in
\vendor\zendframework\zendframework\library\Zend\ServiceManager\AbstractPluginManager.php
on line 180 and defined in \module\Morpho\src\Morpho\Controller\PartOfSpeechController.php on
line 26
Hello, sorry for the late response I was away in holidays and I'm slowly going through my mails…
You are using a YAML config file which is not supported since PHP-DI 4.0! So this doesn't work.
Have a look at the "PHP configuration" section in the documentation: http://php-di.org/doc/definition.html
In your example the config file would be something like that:
(config.php)
<?php
return [
'Morpho\Service\PartOfSpeechService' => DI\object('Morpho\Service\PhpMorphyPartOfSpeechService'),
];
See also this blog post if you are interested to know the details: http://php-di.org/news/06-php-di-4-0-new-definitions.html
Hi Matthieu, thank you very much for support and explanation!
Hi Matthieu,
Could you please give a hint why PHP-DI can be not working for me in integration with Zend2 (reproduced with Apache/2.4.9 (Win64) PHP/5.5.12 and Apache/2.2.22 (Win32) PHP/5.3.13).
composer.json
module/Morpho/config.module.config.php:
config/di.yml:
module/Morpho/src/Morpho/Controller/PartOfSpeechController:
When running this code under apache each time I get:
The injection is working normally if obtain the controller object using container but not under Zend2 MVC. Any your thoughts would be really appreciated.