2015-05-29 35 views
1

我有這樣的基本控制器單一的重定向:重定向循環的笨從基本控制器

class TCMS_Controller extends CI_Controller{ 
    public function __construct(){ 
     parent::__construct(); 
     if(! $this->session->userdata('logged_in')){ 
      redirect('admin/authenticate/login'); 
     } 
     //Loop to get all settings in the "globals" table 
     foreach($this->Settings_model->get_global_settings() as $result){ 
      $this->global_data[$result->key] = $result->value; 
     } 
    } 
} 

所以現在我有這個基本的重定向:如果用戶沒有登錄

redirect('admin/authenticate/login');

我也有這個設置可以從網址中刪除index.php

.htaccess:

Options +FollowSymLinks 
Options -Indexes 
DirectoryIndex index.php 
RewriteEngine on 
RewriteCond $1 !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond ${REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L] 

而旁邊的配置設置:

$config['base_url'] = 'http://something.herokuapp.com/'; 
$config['index_page'] = ''; 

,當我試圖訪問管理部分有一個地址:

http://something.herokuapp.com/admin/controller/method 

如果我沒有登錄,我應該被重定向到login頁面:

http://something.herokuapp.com/admin/authenticate/login 

但是相反,我得到一個重定向循環

ERR_TOO_MANY_REDIRECTS

如何解決呢?

頁: http://tcms.herokuapp.com/

管理部分:http://tcms.herokuapp.com/admin/authenticate/login http://tcms.herokuapp.com/admin/dashobard

+0

請檢查您的瀏覽器控制檯,看看頁面實際上是否嘗試重定向到。 –

+0

你能否顯示你的刷新url鏈接? –

+0

添加鏈接到網站 – Tachi

回答

1

我確定您的admin(可能是authenticate如果管理員是您的文件夾名稱)控制器也延伸TCMS_Controller。因此,當它重定向您的admin控制器時,它會一次又一次地執行TCMS_Controller的構造函數重定向到導致無限循環的管理控制器。

要解決這個問題,您需要製作一個Login控制器,該控制器不會擴展TCMS_Controller只是擴展了CI_Controller.And,如果用戶沒有內嵌,則重定向到此控制器。

+0

admin是我的控制器文件夾中的所有與管理員相關的控制器的子文件夾。 – Tachi