2011-08-17 52 views
0

我今天的問題是這樣的。成功登錄後,我想在重定向時將數據陣列中的user_id發送到控制面板。我在這裏有很多代碼。其中98%的代碼是從認證庫中寫入的,我擔心如果我現在修補得太多,現在我最終會通過嘗試做一件事來破壞別的東西。任何幫助?爲重定向添加數據數組

class Auth extends CI_Controller 
{ 
function __construct() 
{ 
    parent::__construct(); 

    $this->load->helper(array('form', 'url')); 
    $this->load->library('form_validation'); 
    $this->load->library('security'); 
    $this->load->library('tank_auth'); 
    $this->lang->load('tank_auth'); 

    if ($this->tank_auth->is_logged_in()) { 
     redirect('/cpanel/'); 
    } else { 
     redirect('/auth/login/'); 
    }  
} 

function index() 
{ 

} 

/** 
* Login user on the site 
* 
* @return void 
*/ 
function login() 
{ 
    if ($this->tank_auth->is_logged_in()) {         // logged in 
     redirect('/cpanel'); 

    } elseif ($this->tank_auth->is_logged_in(FALSE)) {      // logged in, not activated 
     redirect('/auth/send_again/'); 

    } else { 
     $data['login_by_username'] = ($this->config->item('login_by_username', 'tank_auth') AND 
       $this->config->item('use_username', 'tank_auth')); 
     $data['login_by_email'] = $this->config->item('login_by_email', 'tank_auth'); 

     $this->form_validation->set_rules('login', 'Login', 'trim|required|xss_clean'); 
     $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean'); 
     $this->form_validation->set_rules('remember', 'Remember me', 'integer'); 

     // Get login for counting attempts to login 
     if ($this->config->item('login_count_attempts', 'tank_auth') AND 
       ($login = $this->input->post('login'))) { 
      $login = $this->security->xss_clean($login); 
     } else { 
      $login = ''; 
     } 

     $data['errors'] = array(); 

     if ($this->form_validation->run()) {        // validation ok 
      if ($this->tank_auth->login(
        $this->form_validation->set_value('login'), 
        $this->form_validation->set_value('password'), 
        $this->form_validation->set_value('remember'), 
        $data['login_by_username'], 
        $data['login_by_email'])) {        // success 
       redirect('/cpanel'); 

      } else { 
       $errors = $this->tank_auth->get_error_message(); 
       if (isset($errors['banned'])) {        // banned user 
        $this->_show_message($this->lang->line('auth_message_banned').' '.$errors['banned']); 

       } elseif (isset($errors['not_activated'])) {    // not activated user 
        redirect('/auth/send_again/'); 

       } else {             // fail 
        foreach ($errors as $k => $v) $data['errors'][$k] = $this->lang->line($v); 
       } 
      } 
     } 
     $this->template->set_layout('default')->enable_parser(false); 
     $this->template->build('auth/login_form', $data); 
    } 
} 

編輯:

用下面的代碼,當我去我的kansasoutlawwrestling.com/kowmanager頁我得到一個白色的屏幕,但如果我去我的登錄頁面,這是kansasoutlawwrestling.com/kowmanager/login和登錄然後我得到一個PHP錯誤遇到

嚴重性:注意

消息:未定義的變量:ID

文件名:控制器/ auth.php

行號:63 一個PHP錯誤遇到

嚴重性:警告

消息:無法修改標題信息 - 頭已經發出(輸出開始/家庭/ xtremer /的public_html /系統/核心/ Exceptions.php:170)

文件名:助手/ url_helper.php

行號:543

class Auth extends CI_Controller 
{ 
function __construct() 
{ 
    parent::__construct(); 

    $this->load->helper(array('form', 'url')); 
    $this->load->library('form_validation'); 
    $this->load->library('security'); 
    $this->load->library('tank_auth'); 
    $this->lang->load('tank_auth'); 

    $id = $this->tank_auth->get_user_id(); 

} 

function index() 
{ 

} 

/** 
* Login user on the site 
* 
* @return void 
*/ 
function login() 
{ 
    if ($this->tank_auth->is_logged_in()) {         // logged in 
     redirect('/cpanel', $id); 

    } elseif ($this->tank_auth->is_logged_in(FALSE)) {      // logged in, not activated 
     redirect('/auth/send_again/'); 

    } else { 
     $data['login_by_username'] = ($this->config->item('login_by_username', 'tank_auth') AND 
       $this->config->item('use_username', 'tank_auth')); 
     $data['login_by_email'] = $this->config->item('login_by_email', 'tank_auth'); 

     $this->form_validation->set_rules('login', 'Login', 'trim|required|xss_clean'); 
     $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean'); 
     $this->form_validation->set_rules('remember', 'Remember me', 'integer'); 

     // Get login for counting attempts to login 
     if ($this->config->item('login_count_attempts', 'tank_auth') AND 
       ($login = $this->input->post('login'))) { 
      $login = $this->security->xss_clean($login); 
     } else { 
      $login = ''; 
     } 

     $data['errors'] = array(); 

     if ($this->form_validation->run()) {        // validation ok 
      if ($this->tank_auth->login(
        $this->form_validation->set_value('login'), 
        $this->form_validation->set_value('password'), 
        $this->form_validation->set_value('remember'), 
        $data['login_by_username'], 
        $data['login_by_email'])) {        // success 
       redirect('/cpanel', $id); 

      } else { 
       $errors = $this->tank_auth->get_error_message(); 
       if (isset($errors['banned'])) {        // banned user 
        $this->_show_message($this->lang->line('auth_message_banned').' '.$errors['banned']); 

       } elseif (isset($errors['not_activated'])) {    // not activated user 
        redirect('/auth/send_again/'); 

       } else {             // fail 
        foreach ($errors as $k => $v) $data['errors'][$k] = $this->lang->line($v); 
       } 
      } 
     } 
     $this->template->set_layout('default')->enable_parser(false); 
     $this->template->build('auth/login_form', $data); 
    } 
} 
+2

刪除代碼中的歡迎消息? –

+0

當我登錄後,我得到這個:嗨,[我的屏幕名稱在這裏]!您現在登錄。用註銷鏈接。而不是它顯示我希望它去管理控制器我沒有看到它告訴它加載歡迎消息 –

+1

想到的一個想法是在您的項目中的所有文件中搜索句子 - 它往往最快的方式 –

回答

1

其實@Pekka,tank_auth使用的是語言庫,所以句子不在那裏,而是對英文版句子的引用。您正在尋找的線路是$data['login_by_email'])) { // success之後的文件controllers/auth.php

它使用驗證控制器內部的_show_message()函數。該函數在閃存會話數據中設置消息,然後將您重定向到主驗證視圖(顯示存儲在閃存中的消息)。你可以用簡單的redirect('myControlPanel');替換這條線,你會沒事的。或者做我做的並將它們返回到將它們重定向到登錄頁面的頁面。

希望有幫助, 最大

+0

嘿mazzz你認爲你可以給我發電子郵件嗎?我給你看個東西。 ([email protected]) –

+1

對不起,如果你願意,我們可以開一個聊天室,如果你需要這個問題的進一步幫助。或者你可以發佈你遇到的問題的下一個問題。 – Ben

+0

我們如何開始聊天這個主題? –