在组件内部调用组件10月CMS会出错

时间:2016-11-05 01:09:19

标签: php components extend octobercms

我正在尝试扩展现有的插件组件而且我 需要添加一个函数但是使用插件方法。

我在这里:

<?php namespace Bbrand\Shop\Components;

use Cms\Classes\ComponentBase;
use Jiri\JKShop\Components\Basket;


class Shopextend extends ComponentBase
{

    public function componentDetails()
    {
        return [
            'name'        => 'shopextend Component',
            'description' => 'No description provided yet...'
        ];
    }

    public function defineProperties()
    {
        return [];
    }


    public function onBasket(){

        $data = [];
        $data["basket"] = Basket::getSessionBasket();
        $data["jkshopSetting"] = \Jiri\JKShop\Models\Settings::instance();

        return [ 
            $this->property("idElementWrapperBasketComponent") => $this->renderPartial('@basket-0', $data) 
        ];

    }


}

但我收到错误

  

&#34;非静态方法Jiri \ JKShop \ Components \ Basket :: getSessionBasket()   不应该静态调用&#34;在30号线上   /Applications/MAMP/htdocs/fidgycube.co/plugins/bbrand/shop/components/Shopextend.php

任何帮助!? 感谢

1 个答案:

答案 0 :(得分:0)

您需要先添加组件。

<?php namespace Bbrand\Shop\Components;
class Shopextend extends ComponentBase
{
    public function init()
    {
        // Add component
        $this->addComponent('\Jiri\JKShop\Components\Basket', 'basket', []);
    }
}