Welcome Guest, Not a member yet? Register   Sign In
Beginner : How to debug
#1

[eluser]Unknown[/eluser]
This is my very first time to try CI. I tried to follow tutsplus video with the following scenarion:

Model (post.php):
<?php
class Post extends CI_Model {
function get_posts($num=20, $start=0) {
$this->db->select()->from('posts')->where('active',1)->order_by('date_added', 'desc')->limit($num,$start);
$query = $this->db->get();
return $query->result_array();
}

function get_post($postID){
$this->db->select()->from('posts')->where(array('active'=>1,'postID'=>$postID))->order_by('date_added', 'desc');
$query=$this->db->get();
return $query->first_row('array');
}
...
}

Controller (posts.php):
<?php
class Posts extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->model('post');
}

function index(){
//$this->load->model('post');
$data['posts']=$this->post->get_posts();
$this->load->view('post_index',$data);
}

function post($postID){
$data['post']=$this->post->get_post($postID);
$this->load->view('post',$data);
}
...

View (post.php):
<h1>Blog</h1>
&lt;?php if(!isset($post)) { ?&gt;
<p>The page was accessed incorrectly</p>
&lt;? } else { ?&gt;
<h2>&lt;?=$post['title']?&gt;</h2>
&lt;?=$post['post']?&gt;
&lt;? } ?&gt;

I can browse to localhost/posts and retrieve all posts. But when i click on read more (detail), i got:
Object not found!

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.
Error 404

The url is : http://localhost/posts/post/1

How do I track this error? Thx for any help.




Theme © iAndrew 2016 - Forum software by © MyBB