Object configuration must be an array containing a "class" element.错误是怎么回事

安装报错 · wooecshop · 于 6年前 发布 · 4439 次阅读

Invalid Configuration – yii\base\InvalidConfigException

Object configuration must be an array containing a "class" element.

在win7上安装的,redis和mongodb都安装好了,打开首页时出现下面错误.

public function __get($attr)
{
    return $this->getChildService($attr);
}
// 调用的参数$attr是 image

我看下了下文件:common\config\fecshop_local_services\Image.php return [

'image' => [
    'appbase'    => [
        'appfront' => [
            'basedir'    => '@appimage/appfront',
            'basedomain' => '//img.appfront.fancyecommerce.com',
        ],
        'apphtml5' => [
            'basedir'    => '@appimage/apphtml5',
            'basedomain' => '//img.apphtml5.fancyecommerce.com',
        ],
        //'appadmin' => [
        //	'basedir' => '@appimage/appadmin',
        //	'basedomain' => '//img.appadmin.fancyecommerce.com',
        //],
        'common' => [
            'basedir'    => '@appimage/common',
            'basedomain' => '//img.fancyecommerce.com',
        ],
    ],
],

];

共收到 11 条回复
Fecmall#16年前 0 个赞

把报错信息贴全了,全部贴上来

Fecmall#26年前 0 个赞

你是不是改了哪里的配置了?导致找不到class的配置。

报错信息粘贴补全,无法诊断

wooecshop#36年前 0 个赞

我什么也没有修改。

yii\base\InvalidConfigException: Object configuration must be an array containing a "class" element. in D:\wamp\www\wordpress\vendor\yiisoft\yii2\BaseYii.php:353 Stack trace: #0 D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\services\Application.php(49): yii\BaseYii::createObject(Array) #1 D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\services\Application.php(67): fecshop\services\Application->getChildService('image') #2 D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\services\product\Image.php(69): fecshop\services\Application->get('image') #3 [internal function]: fecshop\services\product\Image->actionGetUrl('/default.jpg') #4 D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\services\Service.php(49): call_user_func_array(Array, Array) #5 D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\services\product\Image.php(103): fecshop\services\Service->__call('getUrl', Array) #6 [internal function]: fecshop\services\product\Image->actionDefautImg() #7 D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\services\Service.php(49): call_user_func_array(Array, Array) #8 D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\services\category\Product.php(90): fecshop\services\Service->call('defautImg', Array) #9 [internal function]: fecshop\services\category\Product->actionConvertToCategoryInfo(Array) #10 D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\services\Service.php(49): call_user_func_array(Array, Array) #11 D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\app\appfront\modules\Cms\block\home\Index.php(50): fecshop\services\Service->__call('convertToCatego...', Array) #12 D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\app\appfront\modules\Cms\block\home\Index.php(28): fecshop\app\appfront\modules\Cms\block\home\Index->getProductBySkus(Array) #13 D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\app\appfront\modules\Cms\block\home\Index.php(19): fecshop\app\appfront\modules\Cms\block\home\Index->getFeaturedProduct() #14 D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\app\appfront\modules\Cms\controllers\HomeController.php(19): fecshop\app\appfront\modules\Cms\block\home\Index->getLastData() #15 [internal function]: fecshop\app\appfront\modules\Cms\controllers\HomeController->actionIndex() #16 D:\wamp\www\wordpress\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array) #17 D:\wamp\www\wordpress\vendor\yiisoft\yii2\base\Controller.php(157): yii\base\InlineAction->runWithParams(Array) #18 D:\wamp\www\wordpress\vendor\yiisoft\yii2\base\Module.php(528): yii\base\Controller->runAction('index', Array) #19 D:\wamp\www\wordpress\vendor\yiisoft\yii2\web\Application.php(103): yii\base\Module->runAction('cms/home/index', Array) #20 D:\wamp\www\wordpress\vendor\yiisoft\yii2\base\Application.php(386): yii\web\Application->handleRequest(Object(fecshop\yii\web\Request)) #21 D:\wamp\www\wordpress\appfront\web\index.php(87): yii\base\Application->run() #22 {main} Copy Stacktrace Search Stackoverflow Search Google Exception Invalid Configuration – yii\base\InvalidConfigException

Object configuration must be an array containing a "class" element.

  1. in D:\wamp\www\wordpress\vendor\yiisoft\yii2\BaseYii.php at line 353 344345346347348349350351352353354355356357358359360361362 if (is_string($type)) {

         return static::$container->get($type, $params);
     } elseif (is_array($type) && isset($type['class'])) {
         $class = $type['class'];
         unset($type['class']);
         return static::$container->get($class, $params, $type);
     } elseif (is_callable($type, true)) {
         return static::$container->invoke($type, $params);
     } elseif (is_array($type)) {
         throw new InvalidConfigException('Object configuration must be an array containing a "class" element.');
     }
    
     throw new InvalidConfigException('Unsupported configuration type: ' . gettype($type));
    

    }

    private static $_logger;

    /**

    • @return Logger message logger
  2. in D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\services\Application.php at line 49 – yii\BaseYii::createObject(['appbase' => ['appfront' => ['basedir' => '@appimage/appfront', 'basedomain' => '//img.appfront.fancyecommerce.co...'], 'apphtml5' => ['basedir' => '@appimage/apphtml5', 'basedomain' => '//img.apphtml5.fancyecommerce.co...'], 'appadmin' => ['basedir' => '@appimage/appadmin', 'basedomain' => 'http://img2.fecshoptest.com'], 'common' => ['basedir' => '@appimage/common', 'basedomain' => '//img.fancyecommerce.com']]]) 43444546474849505152535455
     if (!$this->_childService[$childServiceName]) {
         $childService = $this->childService;
         if (isset($childService[$childServiceName])) {
             $service = $childService[$childServiceName];
             if(!isset($service['enableService']) || $service['enableService']){
                 $this->_childService[$childServiceName] = Yii::createObject($service);
             }else{
                 throw new InvalidConfigException('Child Service ['.$childServiceName.'] is disable in '.get_called_class().', you must config it! ');
             }
         } else {
             throw new InvalidConfigException('Child Service ['.$childServiceName.'] is not find in '.get_called_class().', you must config it! ');
         }
    
  3. in D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\services\Application.php at line 67 – fecshop\services\Application::getChildService('image') 616263646566676869 * @property $attr | String , service的name。
    • 魔术方法,当调用一个属性,对象不存在的时候就会执行该方法,然后
    • 根据构造方法注入的配置,实例化service对象。 */ public function __get($attr) { return $this->getChildService($attr); } }
  4. in D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\services\product\Image.php at line 69 – fecshop\services\Application::__get('image') 63646566676869707172737475 /**

    • 通过产品图片的相对路径得到产品图片的url. */ protected function actionGetUrl($str) { return Yii::$service->image->GetImgUrl($this->imageFloder.$str, 'common'); }

    /**

    • 通过产品图片的相对路径得到产品图片的绝对路径. */ protected function actionGetDir($str)
  5. fecshop\services\product\Image::actionGetUrl('/default.jpg')
  6. in D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\services\Service.php at line 49 – call_user_func_array([fecshop\services\product\Image, 'actionGetUrl'], ['/default.jpg']) 43444546474849505152535455 } else {

         $method = 'action'.ucfirst($originMethod);
         $this->_callFuncLog[$originMethod] = $method;
     }
     if (method_exists($this, $method)) {
         $this->beginCall($originMethod, $arguments);
         $return = call_user_func_array([$this, $method], $arguments);
         $this->endCall($originMethod, $arguments);
    
         return $return;
     } else {
         throw new InvalidCallException('fecshop service method is not exit.  '.get_class($this)."::$method");
     }
    
  7. in D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\services\product\Image.php at line 103 – fecshop\services\Service::__call('getUrl', ['/default.jpg']) 979899100101102103104105106107108109 /**

    • 获取产品默认图片的完整URL */ protected function actionDefautImg() { if (!$this->_defaultImg) {

       $this->_defaultImg = $this->getUrl($this->defaultImg);
      

      }

      return $this->_defaultImg; }

    /**

  8. fecshop\services\product\Image::actionDefautImg()
  9. in D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\services\Service.php at line 49 – call_user_func_array([fecshop\services\product\Image, 'actionDefautImg'], []) 43444546474849505152535455 } else {

         $method = 'action'.ucfirst($originMethod);
         $this->_callFuncLog[$originMethod] = $method;
     }
     if (method_exists($this, $method)) {
         $this->beginCall($originMethod, $arguments);
         $return = call_user_func_array([$this, $method], $arguments);
         $this->endCall($originMethod, $arguments);
    
         return $return;
     } else {
         throw new InvalidCallException('fecshop service method is not exit.  '.get_class($this)."::$method");
     }
    
  10. in D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\services\category\Product.php at line 90 – fecshop\services\Service::__call('defautImg', []) 84858687888990919293949596 /**
    • 将service取出来的数据,处理一下,然后前端显示。 */ protected function actionConvertToCategoryInfo($collection) { $arr = []; $defaultImg = Yii::$service->product->image->defautImg(); if (is_array($collection) && !empty($collection)) {
       foreach ($collection as $one) {
           if (is_array($one['name']) && !empty($one['name'])) {
               $name = Yii::$service->store->getStoreAttrVal($one['name'], 'name');
           } else {
               $name = $one['name'];
      
  11. fecshop\services\category\Product::actionConvertToCategoryInfo([])
  12. in D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\services\Service.php at line 49 – call_user_func_array([fecshop\services\category\Product, 'actionConvertToCategoryInfo'], [[]]) 43444546474849505152535455 } else {

        $method = 'action'.ucfirst($originMethod);
        $this->_callFuncLog[$originMethod] = $method;
    }
    if (method_exists($this, $method)) {
        $this->beginCall($originMethod, $arguments);
        $return = call_user_func_array([$this, $method], $arguments);
        $this->endCall($originMethod, $arguments);
    
        return $return;
    } else {
        throw new InvalidCallException('fecshop service method is not exit.  '.get_class($this)."::$method");
    }
    
  13. in D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\app\appfront\modules\Cms\block\home\Index.php at line 50 – fecshop\services\Service::__call('convertToCategoryInfo', [[]]) 44454647484950515253545556 'special_from', 'special_to',

            'url_key', 'score',
        ];
        $filter['where'] = ['in', 'sku', $skus];
        $products = Yii::$service->product->getProducts($filter);
        //var_dump($products);
        $products = Yii::$service->category->product->convertToCategoryInfo($products);
    
        return $products;
    }
    

    }

    public function initHead()

  14. in D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\app\appfront\modules\Cms\block\home\Index.php at line 28 – fecshop\app\appfront\modules\Cms\block\home\Index::getProductBySkus(['men0003', 'men0002', 'men0001', 'computer001-xinghao2-cpu3', ...]) 22232425262728293031323334 }

    public function getFeaturedProduct() {

    $featured_skus = Yii::$app->controller->module->params['homeFeaturedSku'];
    
    return $this->getProductBySkus($featured_skus);
    

    }

    public function getBestSellerProducts() {

    $bestSellSkus = Yii::$app->controller->module->params['homeBestSellerSku'];
    
  15. in D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\app\appfront\modules\Cms\block\home\Index.php at line 19 – fecshop\app\appfront\modules\Cms\block\home\Index::getFeaturedProduct() 13141516171819202122232425 public function getLastData() {

    $this->initHead();
    // change current layout File.
    //Yii::$service->page->theme->layoutFile = 'home.php';
    return [
        'bestFeaturedProducts'     => $this->getFeaturedProduct(),
        'bestSellerProducts'    => $this->getBestSellerProducts(),
    ];
    

    }

    public function getFeaturedProduct() {

  16. in D:\wamp\www\wordpress\vendor\fancyecommerce\fecshop\app\appfront\modules\Cms\controllers\HomeController.php at line 19 – fecshop\app\appfront\modules\Cms\block\home\Index::getLastData() 13141516171819202122232425 parent::init(); }

    // 网站信息管理 public function actionIndex() {

    $data = $this->getBlock()->getLastData();
    
    return $this->render($this->action->id, $data);
    

    }

    public function behaviors() {

  17. fecshop\app\appfront\modules\Cms\controllers\HomeController::actionIndex()
  18. in D:\wamp\www\wordpress\vendor\yiisoft\yii2\base\InlineAction.php at line 57 – call_user_func_array([fecshop\app\appfront\modules\Cms\controllers\HomeController, 'actionIndex'], [])
  19. in D:\wamp\www\wordpress\vendor\yiisoft\yii2\base\Controller.php at line 157 – yii\base\InlineAction::runWithParams([])
  20. in D:\wamp\www\wordpress\vendor\yiisoft\yii2\base\Module.php at line 528 – yii\base\Controller::runAction('index', [])
  21. in D:\wamp\www\wordpress\vendor\yiisoft\yii2\web\Application.php at line 103 – yii\base\Module::runAction('cms/home/index', [])
  22. in D:\wamp\www\wordpress\vendor\yiisoft\yii2\base\Application.php at line 386 – yii\web\Application::handleRequest(fecshop\yii\web\Request)
  23. in D:\wamp\www\wordpress\appfront\web\index.php at line 87 – yii\base\Application::run() 81828384858687 上面的例子就是获取cms服务的子服务article。 / new fecshop\services\Application($config['services']); unset($config['services']);

$application = new yii\web\Application($config); $application->run(); $_COOKIE = [

'PHPSESSID' => 'gc8r46grouj2gud4em5m0v7dd0',

];

$_SESSION = [

'__flash' => [],
'currency_current' => 'USD',

]; Yii Framework 2017-11-17, 06:36:48

Apache/2.4.23 (Win32) PHP/7.0.10 Yii Framework/2.0.13

wooecshop#46年前 0 个赞

@Terry #2楼 我在百度云上下载的fecshop-1.1.1.3.zip

Fecmall#56年前 0 个赞

@wooecshop #4楼 弄的些什么玩意,把报错信息格式粘贴好,不会去就学习下markdown格式

Fecmall#66年前 1 个赞

问题已解决,该用户安装搞错了,把 vendor\fancyecommerce\fecshop\config\services\Image.php 下的文件给改了。

如图:

wooecshop#76年前 0 个赞

我写了5,6年程序,都一直是c/c++。初次接触电商。感谢大神 @Terry 耐心帮助!

Fecmall#86年前 0 个赞

@wooecshop #7楼 加油,以后学c,多向你请教

Fecmall#96年前 0 个赞

@wooecshop #7楼 建议你学习下markdown格式,就是github readme.md文件的文件需要的那种格式,很简单,学习10个标签就够了

Fecmall#106年前 0 个赞

@wooecshop #7楼 文档更新了

wooecshop#116年前 0 个赞

@Terry 好的,谢谢,相互学习。

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics