Reputation: 337
I am new to CodeIgniter and experiencing the following error after connecting the db . It is really great if some one can help me. I checked previous answers in the StackOverflow but none helped me.
Below is the controller code
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends MY_Controller {
public function index() {
$this->load->view('home');
}
public function adminRegister() {
//loading teh queries model
$this->load->model('queries');
//Calling the getRoles function inside the roles
$roles = $this->queries->getRoles();
print_r($roles);
exit();
$this->load->view('register');
}
public function login() {
echo 'login';
}
}
Model code
<?php
//Details of queries whicha re used to interact with teh database
class Queries extends CI_Model {
//Created a function with the name getRoles
public function getRoles() {
//Fetch the reocrds from the table
$roles = $this->db->get('tbl_roles');
if ($roles->num_rows() > 0) {
return $roles->results();
}
}
}
?>
Currently not using the data coming from controller. Any help will be highly appreciated. Thanks in advance.
Upvotes: 0
Views: 573
Reputation: 5322
There is no results it should be result
Refer CI Doc
class Queries extends CI_Model {
//Created a function with the name getRoles
public function getRoles() {
//Fetch the reocrds from the table
$roles = $this->db->get('tbl_roles');
if ($roles->num_rows() > 0) {
return $roles->result();
}
}
}
Upvotes: 1