2015-10-20 56 views
1

在I remove index.php之后,我在codeigniter中启用查询字符串。但是我有一些重定向链接的问题。详细信息,我有登录表单(登录/索引),登录成功时重定向到“欢迎/索引”并保存会话中的电子邮件。在codeigniter中查询字符串

但是当登录成功时只加载视图“welcome/index”和错误的链接,现在链接是: “?login/index”而session不保存。请帮帮我 。

这里是我的代码

的login.php(控制器)

if($this->input->post('email') != '' && $this->input->post('password') != ''){ 
     if ($this->user->CheckLogin($this->input->post('email'),$this->input->post('password')) == true) 
     { 
      $this->load->library('session'); 
      $this->session->set_flashdata('email', $this->input->post('email')); 
      redirect('welcome/index', 'refresh'); 
     } 
     else 
     { 
      $data['error_message'] = '* Email or Password is incorrect'; 
      $this->load->view('login',$data); 
     } 
    }else{ 
      $this->load->view('login',$data); 
    } 

的welcome.php(控制器)

class Welcome extends CI_Controller { 

public function index() 
    { 
     $this->load->model('user'); 
     $this->load->helper('url'); 
     $this->load->library('session'); 

     $data['email'] = $this->session->flashdata('email'); 
     $this->load->view('welcome_message',$data); 
    } 
} 

welcome_message.php(查看)

<?php 
    // Cant print email 
    echo $email; 
?> 

的.htaccess

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L] 
+0

在你的config.php你做'$配置[ 'uri_protocol'] = 'QUERY_STRING';' – user4419336

+0

感谢。它正在工作,但我所有的链接都有“?”性格。例如:?welcome/index,?login/index。为什么会这样:( – jonny

+0

可能是由于你的htaccess文件在主目录中,如果有的话) – user4419336

回答

0

如果启用查询字符串然后更改重定向这样

redirect('c=welcome &m=index', 'refresh');

此外,它可能需要写index.php?或仅?之前c

或者如果config.php文件,那么你需要改变c and m

$配置变化configuation [ 'enable_query_strings'] = FALSE;
$ config ['controller_trigger'] ='c';
$ config ['function_trigger'] ='m';

更多信息http://www.codeigniter.com/user_guide/general/urls.html#enabling-query-strings

+0

但我使用GET查询没有**启用查询字符串**像这样'htttp://example.com/controller/method/12?filter = no&name = someone' –