This question is related to Appending multiple config arrays in PhalconPHP
I am trying to get retrieve an object from the DI using the get method.
The object is
If your $config variable is an array. You can refer my answer at Missing 'className' parameter
Here is the repost: I found that Phalcon DI container use array for Constructor Injection. So if you set an array into Phalcon DI container, it understands that you want to set an object by using Constructor Injection and it requires "className" definition. You can check this at Constructor Injection section at https://docs.phalconphp.com/3.4/en/di.
Example of constructor injection in the document:
$di->set(
'response',
[
'className' => 'Phalcon\Http\Response'
]
);
$di->set(
'someComponent',
[
'className' => 'SomeApp\SomeComponent',
'arguments' => [
[
'type' => 'service',
'name' => 'response',
],
[
'type' => 'parameter',
'value' => true,
],
]
]
);
MY SOLUTION:
I inject my config as below:
$di->set('myConfigFactory', new MyConfigFactory());
$di->set('config', function () use ($di) {
return $di->get('myConfigFactory')->build();
});
Try this instead in the set:
$di->set('config', function() {
...
return new \Phalcon\Config($new_array);
});
It looks like you're doing $di->set('config', $new_array);
instead of $di->set('config', $config);
:)