仅在用户登录时才能打开Opencart显示模块

时间:2013-10-08 09:03:22

标签: module opencart

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

2 个答案:

答案 0 :(得分:1)

当然,还有一个简单的色彩!

打开例如左列控制器(catalog/controller/common/column_left.php)并在行之后:

protected function index() {

添加此条件(仅限左括号):

    if($this->customer->isLogged()) {

现在找到行

    $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();
    }
}

现在在column_right.phpcontent_bottom.phpcontent_top.php中执行相同操作,您应该完成; - )

编辑:有人可能还想编辑具体的模块控制器并在那里添加条件,但这不会那么简单并且有其他含义 - 仍然会有数据库查询收集所有可用的模块。在我的解决方案中,除了它的简单性之外,还有一个事实是,对于 unlogged 用户,根本不会对模块进行DB调用。

答案 1 :(得分:1)

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

转到我的模块控制器

$this->render();

包裹if(!$this->customer->isLogged()) { $this->render(); }

它运作良好。