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

[eluser]kaos78414[/eluser]
For some reason this brings up a blank page. That's weird because it should at least load my header and footer.

I'm assuming it's passing false for some reason because $blod_id does not have a value? My read more links look like this:
Code:
echo anchor('blog/view/'.$row->blogId, 'Read on');
#12

[eluser]cahva[/eluser]
Well $row->blogId should contain the id right? Ofcourse it doesnt work if theres no id Smile

Does it work if you just use url http://www.yourdomain.com/blog/view/12 (or any other id that exists).
#13

[eluser]kaos78414[/eluser]
The link points to the correct ID. I'm really not sure what's going on here. The database returns results correctly if I just do a simple get('blogposts') active record query.
#14

[eluser]cahva[/eluser]
Just add this to the view method:
Code:
$this->output->enable_profiler(TRUE);

That will tell you the queries run + much more.
#15

[eluser]kaos78414[/eluser]
Weird. No URI data, no queries. Nothing seems to be happening at all. Any ideas?
#16

[eluser]cahva[/eluser]
That is weird. Does that profiler give you anything in other controllers?
#17

[eluser]kaos78414[/eluser]
Nope. Under class/method it says blog/view

Everything else is either benchmarks/memory usage or is empty.
#18

[eluser]cahva[/eluser]
Do you use routes? Thats the only thing that I can think of.. Maybe you should paste the whole controller here so we can have a looksee.
#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;
    }
}


?>
#20

[eluser]cahva[/eluser]
Only thing I see here that could cause problems(but I doubt) is the BlogModel's constructor:
Code:
function Blogmodel() {
    parent::Model();
}
The class itself is CamelCase.. You might just want to use php constructors(you "halfly" use it already in your controller).

You can set the constructor with __construct() in every controller and model:
Code:
function __construct()
{
    parent::__construct();
}
That way you will always dodge spellingerrors.

But as I said, I doubt this causes the error. The error is in uri right now as you dont seem to get any vars passed to your method and is not actually related to the model itself. Do you use any kind of routes(you forgot to say that)?

You said earlier that its not an htaccess issue. You sure? Smile What does profiler say without it(remember to set the index.php as index page in the config while testing)?

If this problem wont solve, you better do an clean CI install and make a test controller to see that uri works as it should.




Theme © iAndrew 2016 - Forum software by © MyBB