2015-05-17 51 views
0

我想創建一個opencart網上商店,其中customerts可以看到內容,如果他們登錄,否則重定向到登錄頁面。我想把它寫入代碼的地方,沒有任何擴展。我在opencart中真的很新。Opencart關閉登錄

回答

1

請下面的目錄/控制器/通用/ header.php文件代碼裏面添加index()功能

if (!$this->customer->isLogged()) { 
     if (!isset($this->request->get['route']) || $this->request->get['route'] != 'account/login') { 

      $this->redirect($this->url->link('account/login', '', 'SSL')); 
     } 
    } 

如果要啓用註冊並登錄,然後執行以下操作:

if (!$this->customer->isLogged()) { 
     if (!isset($this->request->get['route']) || ($this->request->get['route'] != 'account/login' && $this->request->get['route'] != 'account/register')) { 

      $this->redirect($this->url->link('account/login', '', 'SSL')); 
     } 
    } 
+0

這實際上會不斷重定向,因爲標題也用於登錄頁面 –

+0

@JayGilford答案已更新。它現在應該工作。謝謝 – Samir

0
You need add below code 

    if (!$this->customer->isLogged()) { //content code here 
    }else{ $data['content']=''} 

add above code on controller and enclose content so that only login user will be able to see that content. 
and add link "login to view content" and use anchor tag to 
login page 
if($content=''){ 
//redirect code 
}