[eluser]tonanbarbarian[/eluser]
there have been some other posts over the last few days mentioning problems with loading models in the constructor on php4
so try the following code (exactly)
Code:
<?php
class Blogmodel extends Model {
function Blogmodel() {
parent::Model();
}
function get_posts(){
$query = $this->db->get('blog_posts');
return $query->result();
}
function get_all_posts() {
$query = $this->db->query('SELECT * FROM blog_posts');
return $query->result();
}
}
Code:
<?php
class blog extends Controller{
function Blog(){
parent::Controller();
}
function index(){
$this->load->model('Blogmodel', 'blog', true);
$data['title'] = "Titolo del blog";
$data['heading'] = "Primo Blog";
$data['query'] = $this->blog->get_posts();
die (print_r($data));
}
function all() {
$this->load->model('Blogmodel', 'blog', true);
$data['title'] = "Titolo del blog";
$data['heading'] = "Primo Blog";
$data['query'] = $this->blog->get_all_posts();
die (print_r($data));
}
}
The changes I have made are to change
Code:
return = $query->result();
to
Code:
return $query->result();
as per xwero's suggestion
and to move the load->model into the index method rather than the constructor
finally I have created a second method in the model and controller
so if the blog/index does not work try going to blog/all
If blog/all works and blog/index does not then you have not turned on active records in the database config
Code:
$db['default']['active_r'] = TRUE;