Welcome Guest, Not a member yet? Register   Sign In
Trying to show a single blog post
#19

[eluser]kaos78414[/eluser]
Here's the controller blog.php

Code:
<?php

// Blog controller

class Blog extends Controller
{
    function __construct(){
        parent::Controller();
        $this->load->model('blogmodel');
        $this->load->helper('text');
    }
    
    function index(){
        $data['posts'] = $this->blogmodel->get_recent_entries(); // Get blog posts
        $data['content'] = 'blogview';
        
        $this->load->view('includes/template', $data);
    }
    
    function view($blog_id = FALSE) {
        $this->output->enable_profiler(TRUE);
        if (!$blog_id)
        {
            return FALSE;
        }
    
        $data['post'] = $this->blogmodel->get_view($blog_id);
    
        if (!$data['post'])
        {
            // Maybe check the $data['post'] here and load a error view for non existing blogid
            $this->load->view('error_404');
            return FALSE;
        }
    
        $data['content'] = 'postview';

        $this->load->view('includes/template', $data);
    }
    
}

?>

And this is the entire model file at blogmodel.php
Code:
<?php
// Blog model

class BlogModel extends Model{
    
    function Blogmodel() {
        parent::Model();
    }
    
    function get_recent_entries()
    {
        $query = $this->db->get('blogposts', 10);
        return $query->result();
    }
    
    function get_view($blog_id)
    {
        $this->db->where('blogId', $blog_id);
        $query = $this->db->get('blogposts');
    
        if ($query->num_rows() == 1) {
            return $query->result();
            }
    
        return FALSE;
    }
}


?>


Messages In This Thread
Trying to show a single blog post - by El Forum - 05-20-2010, 06:53 AM
Trying to show a single blog post - by El Forum - 05-20-2010, 06:56 AM
Trying to show a single blog post - by El Forum - 05-20-2010, 07:26 AM
Trying to show a single blog post - by El Forum - 05-20-2010, 09:53 AM
Trying to show a single blog post - by El Forum - 05-20-2010, 10:00 AM
Trying to show a single blog post - by El Forum - 05-20-2010, 10:01 AM
Trying to show a single blog post - by El Forum - 05-20-2010, 10:01 AM
Trying to show a single blog post - by El Forum - 05-20-2010, 11:23 AM
Trying to show a single blog post - by El Forum - 05-20-2010, 11:32 AM
Trying to show a single blog post - by El Forum - 05-20-2010, 11:49 AM
Trying to show a single blog post - by El Forum - 05-20-2010, 11:58 AM
Trying to show a single blog post - by El Forum - 05-20-2010, 12:10 PM
Trying to show a single blog post - by El Forum - 05-20-2010, 12:24 PM
Trying to show a single blog post - by El Forum - 05-20-2010, 12:53 PM
Trying to show a single blog post - by El Forum - 05-20-2010, 12:58 PM
Trying to show a single blog post - by El Forum - 05-20-2010, 01:10 PM
Trying to show a single blog post - by El Forum - 05-20-2010, 01:15 PM
Trying to show a single blog post - by El Forum - 05-20-2010, 01:23 PM
Trying to show a single blog post - by El Forum - 05-20-2010, 01:29 PM
Trying to show a single blog post - by El Forum - 05-20-2010, 03:15 PM
Trying to show a single blog post - by El Forum - 05-20-2010, 05:17 PM
Trying to show a single blog post - by El Forum - 05-20-2010, 05:33 PM
Trying to show a single blog post - by El Forum - 05-20-2010, 05:46 PM
Trying to show a single blog post - by El Forum - 05-20-2010, 05:57 PM
Trying to show a single blog post - by El Forum - 05-21-2010, 12:51 AM
Trying to show a single blog post - by El Forum - 05-21-2010, 01:34 AM
Trying to show a single blog post - by El Forum - 05-21-2010, 07:44 AM
Trying to show a single blog post - by El Forum - 05-22-2010, 06:02 AM
Trying to show a single blog post - by El Forum - 05-24-2010, 09:04 AM
Trying to show a single blog post - by El Forum - 05-24-2010, 10:10 AM
Trying to show a single blog post - by El Forum - 05-24-2010, 12:28 PM



Theme © iAndrew 2016 - Forum software by © MyBB