“无效服务定义";使用DI-> Get Phalcon PHP时 [英] "Invalid Service Definition" when using DI->Get Phalcon PHP
本文介绍了“无效服务定义";使用DI-> Get Phalcon PHP时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用get方法从DI中检索对象.
I am trying to get retrieve an object from the DI using the get method.
对象是这样设置的
// $new_array the array with the merged data. Load it in a
// \Phalcon\Config object
$config = new \Phalcon\Config($new_array);
//Store the config in your DI container for easier use
$di->set('config', $config);
这是我打电话时收到的错误消息
And this is the error message I am getting when I call
$new_array = $di->get('config');
[带有消息无效"的未捕获异常"Phalcon \ DI \ Exception" 服务定义.缺少"className"参数']
[Uncaught exception 'Phalcon\DI\Exception' with message 'Invalid service definition. Missing 'className' parameter']
我已经坚持了几天,因此,我将不胜感激.
I have been stuck on this for a few days now so would greatly appreciate any help I can get.
推荐答案
在集合中尝试以下方法:
Try this instead in the set:
$di->set('config', function() {
...
return new \Phalcon\Config($new_array);
});
这篇关于“无效服务定义";使用DI-> Get Phalcon PHP时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文