$this->config->get()

发布于 2024-12-04 13:08:54 字数 792 浏览 2 评论 0原文

我正在阅读别人的代码(需要对其进行一些更改),并且我陷入了这个功能。它可能与 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)和它扩展自的类(扩展控制器)都没有这些,这就是为什么我问...

I'm reading someone else's code (need to make some changes in it) and I'm stuck at this function. Its probably related to MVC approach and is common on the web (i found a lot of google results) but i couldn't find what it actually does.

I'm guessing it's a standard method common to major MVC-based CMSes/PHP platforms, but I can't find where it's coded or what it does?

here's the code snippet for reference

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'];     
            }
        }

I understand that there must be an object config with a method get()

But neither the class that contains this code (class ControllerCommonColumnLeft), nor the class that it extends from (extends Controller) has any of these, that is why I ask...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不忘初心 2024-12-11 13:08:54

这取决于它在哪里使用。在 PHP 中,$this 指的是“当前类”,因此,例如,在下面的代码中,$this 就像是在说“在类中查找” Person for ...”

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 类,情况可能会有点复杂,但您现在不必担心这些。

It depends where it's used. In PHP, $this refers to "the current class", so if you have, for example, in the following code, $this is like saying "Look in the class Person for ..."

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');

It can be a little more complicated once you start using static classes, but you shouldn't worry about those for now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文