$this->config->get()


$this->config->get()

我正在阅读别人的代码(需要在其中进行一些更改),我被困在这个函数。它可能与MVC方法有关,在网络上很常见(我发现了很多谷歌结果),但我找不到它实际做什么。

我猜这是一个标准的方法常见的主要mvc为基础的cms/PHP平台,但我找不到它的编码或它做什么?

下面是参考

的代码片段
foreach ($results as $result) {
            if ($this->config->get($result['key'] . '_status') && ($this->config->get($result['key'] . '_position') == 'left')) {
                $module_data[] = array(
                    'code'       => $result['key'],
                    'sort_order' => $this->config->get($result['key'] . '_sort_order')
                );
                $this->children[] = 'module/' . $result['key'];     
            }
        }

我明白必须有一个对象配置方法get()

但是包含此代码的类(类ControllerCommonColumnLeft)和它扩展的类(extends Controller)都没有这些,这就是为什么我问…

这取决于它的使用位置。在PHP中,$this指的是"当前类",所以如果你有,例如,在下面的代码中,$this就像在说"在类Person中查找…"

class Person
{
    public function walk ($to)
    {
        echo 'I walked to ' . $to . '<br />';
    }
    public function eat ($food, $place)
    {
        // Here, $this->walk() calls Person->walk(), as '$this class' is called Person
        $this->walk($place);
        echo 'I ate a ' . $food . ' at ' . $place;
    }
}
$person = new Person;
$person->eat('jelly bean', 'the sweet shop');

一旦您开始使用static类,它可能会稍微复杂一些,但是您现在不应该担心这些。