【问题标题】:codeigniter: call Index Method from another methodcodeigniter:从另一个方法调用索引方法
【发布时间】:2013-05-21 22:27:00
【问题描述】:

我是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();                   
        }
    }
}

“authen”方法在其最后条件下无法正常工作。页面不重定向到控制器。

有人可以帮忙吗? 谢谢

【问题讨论】:

    标签: codeigniter


    【解决方案1】:

    您可以使用:redirect('user') 它会将您重定向到控制器用户类

    【讨论】:

    【解决方案2】:

    代替

    $this->index();
    

    试试这个

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

    【讨论】:

      【解决方案3】:

      您正在尝试加载登录页面,以防出现任何身份验证错误。

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

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

      或显示验证错误..

      您不能从控制器调用控制器。如 $this->index();

      【讨论】:

        猜你喜欢
        • 2020-07-18
        • 2016-07-02
        • 2015-06-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-24
        相关资源
        最近更新 更多