gpt4 book ai didi

php - 页面加载错误codeigniter

转载 作者:行者123 更新时间:2023-11-30 21:47:41 25 4
gpt4 key购买 nike

提供持有域列表的小型 codeigniter 项目。在登录页面之后,您将被重定向到数据库中的域列表。运行这个页面(域列表)没有问题。唯一的问题是当您从登录名调用此页面时。登录页面没有问题(下面是登录 Controller )。

public function index(){
$this->load->view('login');
}
public function checklogin()
{
$this->form_validation->set_rules('username','Username','required');
$this->form_validation->set_rules('password','Password','required|callback_verifyUser');

if($this->form_validation->run() == false){
$this->load->view('login');
}else{
$this->load->view('home');
}
}
public function verifyUser(){
$User = $this->input->post('username');
$Pwd = $this->input->post('password');

$this->load->model('Loginmodel');
if($this->Loginmodel->login($User,$Pwd)){
return true;
}else{
$this->form_validation->set_message('verifyUser','Incorrect Login Details');
return false;
}
}

对“home”索引的调用似乎是问题所在(下面的代码)首页模型

public function getPosts()
{
$result = array();
$this->db->select('*');
$this->db->from('domains');
$this->db->where('Active','Y');
$this->db->order_by('ExpDate','ASC');
//$query= $this->db->query("select * from baldwin_domains where Active ='Y' order by ExpDate ASC");
$query = $this->db->get();
if($query->num_rows()>0){
return $query->result();
}
}

主页 Controller :

public function index()
{
$this ->load->model('Crudmodel');
$records = $this->Crudmodel->getPosts();
$this->load->view('home', ['records' => $records]);
}

删除登录名,没有问题,所有页面都可以正常工作。这是错误:

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: records

Filename: views/home.php
Line Number: 17
Backtrace:
File: C:\xampp\htdocs\domainsys\application\views\home.php
Line: 17
Function: _error_handler
File: C:\xampp\htdocs\domainsys\application\controllers\Login.php
Line: 15
Function: view
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/home.php
Line Number: 17
Backtrace:
File: C:\xampp\htdocs\domainsys\application\views\home.php
Line: 17
Function: _error_handler
File: C:\xampp\htdocs\domainsys\application\controllers\Login.php
Line: 15
Function: view

最佳答案

问题是当用户输入有效凭据时,您将加载 View home。但是您没有将任何参数传递给 View 。

通过查看主 Controller ,我假设您正在主页(Home View )上呈现一个帖子列表。因此,您必须将他重定向到家庭 Controller ,而不是加载 View 。

尝试使用登录后 redirect('home','refresh') 而不是 $this->load->view('home')

public function checklogin()
{
$this->form_validation->set_rules('username', 'Username','required');
$this->form_validation->set_rules ('password','Password','required|callback_verifyUser');

if($this->form_validation->run() == false){
$this->load->view('login');
}else{
redirect('home','refresh');
}
}

重定向将他带到家庭 Controller 并呈现所需内容。

public function index()
{
$this ->load->model('Crudmodel');
$records = $this->Crudmodel->getPosts();
$this->load->view('home', array('records' => $records));
}

关于php - 页面加载错误codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48688528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com