[eluser]Deep Arora[/eluser]
I have following code (from the docs) that I am trying out to get a feel of CI..
VIEW: blog_view.php
Code:
<html>
<head>
<title>{blog_title}</title>
</head>
<body>
<h3>{blog_heading}</h3>
{blog_entries}
<h5>{post_title}</h5>
<p>{post_content}</p>
{/blog_entries}
</body>
</html>
CONTROLLER: blog.php
Code:
<?php
class Blog extends Controller {
function Blog()
{
parent::Controller();
}
function index()
{
[b]$query = $this->db->query("SELECT * FROM site_posts");[/b]
$this->load->library('parser');
$data = array(
'blog_title' => 'My Blog Title',
'blog_heading' => 'My Blog Heading',
[b]'blog_entries' => $query->result_array()[/b]
);
$this->parser->parse('blog_view', $data);
//$this->load->view('blog_view', $data);
}
}
/* End of file blog.php */
/* Location: ./system/application/controllers/blog.php */
Now as you can see, I am using the SQL QUERY in the controller. But I want to use it in the MODEL. When I write a model as :
MODEL: blog_model.php
Code:
class Blog_model extends Model {
function Blog_model()
{
// Call the Model constructor
parent::Model();
}
function get_last_ten_entries()
{
$query = $this->db->get('site_posts', 10);
return $query->result();
}
}
...what should I change the following lines in the controller to?
Code:
[b]$query = $this->db->query("SELECT * FROM site_posts");[/b]
[b]'blog_entries' => $query->result_array()[/b]
I tried this:
Code:
$this->load->model('Blog_model');
$result_set['blog_posts'] = $this->Blog_model->get_last_ten_entries();
[b]'blog_entries' => $result_set[/b]
but it didn't work..
Any help pls?