M
M
Mark2021-12-23 13:37:22
Yii
Mark, 2021-12-23 13:37:22

Why can't Yii2 inject dependency and throw NotInstantiableException?

Exception 'yii\di\NotInstantiableException' with message 'Can't instantiate core\lib\goodsProvider\GoodsBuffer.'

There is a GoodsBuffer class - it itself without a constructor:
kiss_11kb.1640255549.png

It must be thrown as a dependency into the JackFinder class, GoodsBuffer goes as the 2nd parameter:
kiss_7kb.1640255614.png

I get an exception: Exception 'yii\di\NotInstantiableException' with message 'Can not instantiate core\lib\goodsProvider\GoodsBuffer .'

Exception 'yii\di\NotInstantiableException' with message 'Can not instantiate core\lib\goodsProvider\GoodsBuffer.'

in E:\Program\OpenServer\domains\work\martashop.loc\vendor\yiisoft\yii2\di\Container.php:543

Stack trace:
#0 E:\Program\OpenServer\domains\work\martashop.loc\vendor\yiisoft\yii2\di\Container.php(386): yii\di\Container->getDependencies('core\\lib\\jack...')
#1 E:\Program\OpenServer\domains\work\martashop.loc\vendor\yiisoft\yii2\di\Container.php(171): yii\di\Container->build('core\\lib\\jack...', Array, Array)
#2 E:\Program\OpenServer\domains\work\martashop.loc\core\lib\goodsProvider\ProviderFactory.php(81): yii\di\Container->get('core\\lib\\jack...')
#3 E:\Program\OpenServer\domains\work\martashop.loc\core\lib\goodsProvider\ProviderFactory.php(65): core\lib\goodsProvider\ProviderFactory->creator('jack', Array, 'core\\lib\\goodsP...')
#4 E:\Program\OpenServer\domains\work\martashop.loc\core\services\goods\import\GoodsUpdater.php(28): core\lib\goodsProvider\ProviderFactory->createFinderClass('jack')
#5 E:\Program\OpenServer\domains\work\martashop.loc\console\controllers\GoodsController.php(77): core\services\goods\import\GoodsUpdater->update(Object(core\entities\Goods\Goods))
#6 [internal function]: console\controllers\GoodsController->actionUpdate()
#7 E:\Program\OpenServer\domains\work\martashop.loc\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
#8 E:\Program\OpenServer\domains\work\martashop.loc\vendor\yiisoft\yii2\base\Controller.php(181): yii\base\InlineAction->runWithParams(Array)
#9 E:\Program\OpenServer\domains\work\martashop.loc\vendor\yiisoft\yii2\console\Controller.php(184): yii\base\Controller->runAction('update', Array)
#10 E:\Program\OpenServer\domains\work\martashop.loc\vendor\yiisoft\yii2\base\Module.php(534): yii\console\Controller->runAction('update', Array)
#11 E:\Program\OpenServer\domains\work\martashop.loc\vendor\yiisoft\yii2\console\Application.php(181): yii\base\Module->runAction('goods/update', Array)
#12 E:\Program\OpenServer\domains\work\martashop.loc\vendor\yiisoft\yii2\console\Application.php(148): yii\console\Application->runAction('goods/update', Array)
#13 E:\Program\OpenServer\domains\work\martashop.loc\vendor\yiisoft\yii2\base\Application.php(392): yii\console\Application->handleRequest(Object(yii\console\Request))
#14 E:\Program\OpenServer\domains\work\martashop.loc\yii(23): yii\base\Application->run()
#15 {main}


1. Namespace is specified correctly in accordance with the autoloader standard:
kiss_11kb.1640255778.png

2. The autoloader must also see the core directory: it even contains FinderInterface, which implements JackFinder.

What could be the problem?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mark, 2021-12-23
@MarkLb

Hang up. I guessed to call the class without DI, through new:

public function __construct()
    {
        $this->buffer = new GoodsBuffer();
    }

Got an error from PHP. I forgot to change the version in the console:
Exception 'ParseError' with message 'syntax error, unexpected 'array' (T_ARRAY), expecting function (T_FUNCTION) or const (T_CONST)'

It was necessary to think of calling through new right away - it would save an hour of time.

D
Dmitry Kovalsky, 2015-08-13
@dmitryKovalskiy

Try like this

SELECT id,SUM(кол-во)
GROUP BY id
HAVING SUM(кол-во) > someValue

P
Pavel, 2015-08-14
@pauloa

SELECT *
FROM table1
WHERE id IN ( select id 
from table1 GROUP BY id
HAVING SUM(кол-во)) >= 2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question