Module 仅当用户登录时才显示Opencart模块

Module 仅当用户登录时才显示Opencart模块,module,opencart,Module,Opencart,opencart中是否有任何方法仅为登录用户显示边栏模块?当然,还有一个简单的共谋 打开左栏控制器(catalog/controller/common/column_left.php),在该行之后: protected function index() { 添加此条件(仅限开口括号): 现在找到线 $this->render(); 在之前添加以下内容: } else { $this->data['modules'] = array(); }

opencart中是否有任何方法仅为登录用户显示边栏模块?

当然,还有一个简单的共谋

打开左栏控制器(
catalog/controller/common/column_left.php
),在该行之后:

protected function index() {
添加此条件(仅限开口括号):

现在找到线

    $this->render();
在之前添加以下内容:

    } else {
        $this->data['modules'] = array();
    }
最后的代码应该是这样的:

<?php  
class ControllerCommonColumnLeft extends Controller {
    protected function index() {
        if($this->customer->isLogged()) {
            // ... all the previous code up to the render() call
        } else {
            $this->data['modules'] = array();
        }

        $this->render();
    }
}

感谢您的快速回复。我找到了一个简单的解决办法

转到我的模块控制器

包装的
$this->render()if(!$this->customer->isloged()){$this->render();}


它工作得很好。

是的,但请检查我在回答末尾的注释-在这种情况下,所有模块都已填充,模块内的所有逻辑都已完成,即使用户未登录。这意味着许多对未标记的用户不必要的DB查询被执行。。。我的解决方案,当包装所有方法的代码时,会更好。
<?php  
class ControllerCommonColumnLeft extends Controller {
    protected function index() {
        if($this->customer->isLogged()) {
            // ... all the previous code up to the render() call
        } else {
            $this->data['modules'] = array();
        }

        $this->render();
    }
}