Php 在POST方法上加载视图或重定向
我正在尝试加载视图或在POST方法上重定向。但是我做不到Php 在POST方法上加载视图或重定向,php,codeigniter,Php,Codeigniter,我正在尝试加载视图或在POST方法上重定向。但是我做不到 if($_POST){ $this->load->model('Staff_model'); $username = $this->input->post('username'); $password = $this->input->post('password'); if(!empty($username) && !
if($_POST){
$this->load->model('Staff_model');
$username = $this->input->post('username');
$password = $this->input->post('password');
if(!empty($username) && !empty($password)){
$result = $this->Staff_model->getUserByUsernameAndPassword($username, $password);
if($result){
$sess_array = array();
$sess_array = array(
'id' => $result['id'],
'username' => $result['username'],
'name' => $result['name'],
'status' => $result['status']
);
$this->session->set_userdata('logged_in', $sess_array);
redirect('dashboard', 'refresh');
}else{
$this->load->view('login_view');
}
}
在上面的代码中,如果$result变为false,我需要加载“login\u view”视图。或者我需要重定向到仪表板控制器。但无论哪种情况,我都会得到空白页
这是完整的代码
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
if($_POST){
$this->load->model('Staff_model');
$username = $this->input->post('username');
$password = $this->input->post('password');
if(!empty($username) && !empty($password)){
$result = $this->Staff_model->getUserByUsernameAndPassword($username, $password);
if($result){
$sess_array = array();
$sess_array = array(
'id' => $result['id'],
'username' => $result['username'],
'name' => $result['name'],
'status' => $result['status']
);
$this->session->set_userdata('logged_in', $sess_array);
redirect('dashboard', 'refresh');
}else{
$this->load->view('login_view');
}
}
}else{
$this->load->view('login_view');
}
}
}
U像这样发送值
$this->load->view('login_view',$sess_array);
并在查看页面中回显所需的值
echo $sess_array('username');
你能显示完整的代码吗?如果你在最后到达,也试着在这两种情况下回应。也发布你的模型代码!!你们试过回显了吗?是的,我可以回显,登录功能正常。我的问题是我无法在post方法中加载视图。我的意思是,在加载视图的位置进行回音,以查看条件是否有效。