codeigniter也在重定向上加载相同的视图

6l7fqoea  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(257)

我试图重定向到一个控制器中的一个特定功能,而做登录,它的工作,但它加载相同的视图。我的代码在下面

class Authentication extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('Authentication_model');
        $this->load->model('Common_model'); 
        $this->load->library('form_validation');
    }

    public function index() {

        if ($this->session->userdata('user_id')) { 
            //If the user is Super Admin
            if ($this->session->userdata('role') == 'Super Admin') {   
                redirect("Admin/adminProfile");
            }elseif ($this->session->userdata('role') == 'Admin') {
                redirect("Outlet/outlets");
            } else {   
                redirect("Authentication/userProfile");
            }
        }

        $this->load->view('authentication/login');
    }
    public function test() {
        die('hi');
    }

看法

<div class="login-box-body">

                <p class="login-box-msg">Please Login</p> 

                <?php echo form_open(base_url('Authentication/test')); ?>
                <div class="form-group has-feedback">
                    <input type="text" class="form-control" name="email_address" placeholder="Email Address">
                    <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
                </div>

                <?php if (form_error('email_address')) { ?>
                    <div class="alert alert-error" style="padding: 5px !important;">
                        <p><?php echo form_error('email_address'); ?></p>
                    </div>
                <?php } ?>

                <div class="form-group has-feedback">
                    <input type="password" name="password" class="form-control" placeholder="Password">
                    <span class="glyphicon glyphicon-lock form-control-feedback"></span>
                </div>

                <?php if (form_error('password')) { ?>
                    <div class="alert alert-error" style="padding: 5px !important;">
                        <p><?php echo form_error('password'); ?></p>
                    </div>
                <?php } ?>

                <div class="row"> 
                    <!-- /.col -->
                    <div class="col-xs-12">
                        <button type="submit" name="submit" value="submit" class="btn btn-primary btn-block btn-flat">Login</button>
                    </div>
                    <!-- /.col -->
                </div>
                <?php echo form_close(); ?>

            </div>

现在,当我登录它去下面的链接
baseurl.com/authentication/test
并再次加载相同的登录视图。有什么问题吗

slwdgvem

slwdgvem1#

试着换这条线

if ($this->session->userdata('user_id')) {

用这个

if ($this->session->has_userdata('user_id')) {

相关问题