Small codeigniter project that supplies listing of held domains. After the login page you are redirected to the list of domains from the database. Run this page (the list of doamins) and there is no problem. The only problem is when you call this page from the login. The login page is no problem (login controller below).
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;
}
}
The call to the 'home' index seem to be the problem (code below) Home page model
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();
}
}
The home page controller:
public function index()
{
$this ->load->model('Crudmodel');
$records = $this->Crudmodel->getPosts();
$this->load->view('home', ['records' => $records]);
}
remove the login and there is no problem all pages work fine. This is the error:
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