2013-05-27 72 views
0

我是CodeIgniter中的新成员。我遇到了问题。我的程序似乎合乎逻辑,但它不起作用!codeigniter:从另一种方法调用索引方法

我有一个控制器:User

class User extends CI_Controller { 

    public function __construct() { 
     parent::__construct(); 
     $this->load->model('user_model'); 
    } 

    public function index($slug = FALSE) { 
     $data['title'] = "User List"; 
     if($slug === FALSE) { 
      $data['user'] = $this->user_model->get_user();  
     } else { 
      $data['user'] = $this->user_model->get_user($slug);  
     }  
     if (empty($data['user'])){ 
      show_404(); 
     } 
     $this->load->library('table');   
     $this->load->view('user_view', $data);  
    } 

    public function authen() { 
     $this->load->helper('form'); 
     $this->load->library('form_validation');  

     $this->form_validation->set_rules('phone', 'phone', 'required'); 
     $this->form_validation->set_rules('password', 'password', 'required'); 

     if ($this->form_validation->run() === FALSE) { 
      $this->load->view('login_form'); 
     } else { 
      if($this->user_model->do_login()===TRUE) { 
       $this->index(); 
      }  
      $this->authen();     
     } 
    } 
} 

的“认证介绍”方法不使用其最后条件正常工作。页面不重定向到控制器。

任何人都可以帮忙吗? 感谢

回答

1

你可以使用:redirect('user')将ü重定向到控制器的用户类

+0

谢谢,它的工作原理。但为什么不$ this-> index()不起作用?事实上,几个谷歌网站这么说... –

+0

尝试检查这一个:http://stackoverflow.com/questions/723883/redirect-with-codeigniter –

0

而不是

$this->index(); 

试试这个

header('Location:http://myipaddress/mysite/user'); 
0

您在尝试加载登录页面如果有任何验证错误。

为此,您需要重新将用户带到登录页面。

使用重定向('user/login');并将错误消息存储在会话闪存中。

或显示验证错误..

你不能从一个控制器,呼叫控制器。 as $ this-> index();

相关问题