【问题标题】:Call component inside component October CMS gives an error组件十月 CMS 内的调用组件报错
【发布时间】:2017-03-18 22:40:54
【问题描述】:

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

这里有什么:

<?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) 
        ];

    }


}

但是我遇到了一个错误

"非静态方法Jiri\JKShop\Components\Basket::getSessionBasket() 不应该被静态调用”在第 30 行 /Applications/MAMP/htdocs/fidgycube.co/plugins/bbrand/shop/components/Shopextend.php

有什么帮助!? 谢谢

【问题讨论】:

  • 调用静态 == ::,在这种情况下不是指-&gt;
  • 那我怎么称呼它?!
  • 答案应该就在眼前,即使没有我的评论……这是 PHP OOP 的基础。 $data["basket"] = Basket::getSessionBasket(); 被静态调用,错误消息明确指出 not 这样做。现在阅读我的第一条评论。
  • 非常有帮助!你聪明,谢谢

标签: php components extend octobercms


【解决方案1】:

你需要先添加组件。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-22
    • 1970-01-01
    • 2019-07-21
    • 1970-01-01
    • 2017-07-19
    • 1970-01-01
    • 2016-09-11
    • 2017-07-18
    相关资源
    最近更新 更多