[eluser]LeonardoRaygoza[/eluser]
this is my database configuration:
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "";
$db['default']['database'] = "mvcprueba";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
I fixed the model as Flaky said and now the model can be loaded, but when I'm trying to show the entries on the view I get the error: Fatal error: Call to a member function result_array() on a non-object in C:\wamp\www\mvc\system\application\views\blog_view.php on line 13
my view code is:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html >
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=utf-8” />
<title>Leo’s Blog</title>
</head>
<body>
<h1>This is my blog!</h1>
<?php
foreach($query->result_array() as $row) <- this is my line 13
{
echo $row['id_usuario'];
echo $row['nombre'];
echo $row['usuario'];
echo $row['password'];
}
?>
</body>
</html>
My model fixed:
<?php
class Blog_model extends Model {
function Blog_model()
{
parent::Model();
$this->load->database();
}
function get_entries()
{
$query = $this->db->query('Select * from user');
return $query->result_array();
}
}
?>
and my controller:
<?php
class Blog extends Controller{
function Blog()
{
parent::Controller();
}
function index()
{
$this->load->model('blog_model');
$data['query'] = $this->blog_model->get_entries();
$this->load->view('blog_view', $data);
}
}
?>
I really don't understand why Im getting the error, maybe Im missing something...
thanks for help