duanbeng1923 2015-12-26 09:14
浏览 58

如何在CodeIgniter中的方法中加载控制器构造函数的视图?

I'm fairly new to CI and am trying to redirect a user to a view, with my own data, from a method inside a controller, like so:

class Welcome extends CI_Controller {

    public function doLogin() {
        extract($_POST);
        $this->load->library("form_validation");
        $this->form_validation->set_rules('email', 'Email', 'required|trim|valid_email');
        $this->form_validation->set_rules('password', 'Password', 'required|trim');
        if ($this->form_validation->run() == FALSE)
        {
            exit;
        }
        else {
            if ($this->welcome_model->loginuser($email,$password)==true) {
                header("Location: ".base_url()."explore");
            }
            else {
                $data['errors'][] = "Email and password do not match.";
                $this->load->view('header');
                $this->load->view('welcome',$data);
            }
            return true;
        }
    }
}

As you can see the lower part is supposed to load /welcome, but instead loads /welcome/doLogin

Is there a way to load the view like the constructor? so it will load /welcome only?

  • 写回答

1条回答 默认 最新

  • duanshaiduhao2471 2015-12-26 10:08
    关注

    You are currently using welcome/doLogin to load view and you want that how to load (view) / doLogin by just visiting welcome .

    To do so,

    public function index(){
         $this->doLogin();
    }
    

    By using this funtion. Whenever you will open welcome page it will redirect you to doLogin() function automatically.

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类