Welcome Guest, Not a member yet? Register   Sign In
i need help to code the view section of a blog engine
#1

[eluser]ebot[/eluser]
Hi all

please i will like any one to help me to code the view from this piece of codes i will be grateful for your help


this is the model:

<?php
class Blog_model extends Model {

function blog_model()
{
parent::Model();

}
// get the blog entry the user clicked on
function getpost($id)
{
$this->db->select("post_id, title, date_format(postdate, '%e %b %Y
at %H:%i') as datetime, post");
$this->db->where(array('post_id'=>$id));
$query=$this->db->get('blogpost');
return $query->result();
}

function insertcomm($data)
{
$this->db->insert('comments',$data);
}

function getcomments($id)
{
$query=$this->db->getwhere('comments',array('post_id'=>$id));
return $query;
}

function commentnum($id)
{
$query=$this->db->getwhere('comments',array('post_id'=>$id));
return $query->num_rows();
}

}
?>





this is the controller:

<?php
// recrticting direct access
if (!defined('BASEPATH')) die("Access denied");

class blog extends Controller {

function blog() {

parent::Controller();

// loading blog model
$this->load->model('Blog');
}

function index()
{
// on index page we will select latest blog entries.
/*You will have to write function get_latest_entries($range) on
your blog model
accepting one parameter and return a array of results. */
$resent_posts = $this->Blog->get_latest_entries(5);

$this->load->view('front/blog_home', $resent_posts);
}

function display_post($post_id)
{
// retrieve entry data and display
$entry_data = $this->Blog->getpost($post_id);
$this->load->view('front/blog_entry', $entry_data);

// retrieve comments and display
$entry_comments = $this->Blog->getcomments($post_id)
$this->load->view('front/comment_view', $entry_comments);

// www.example.com/display_post/12/ will display entry id 12 and
related comments to entry id 12
}

function insert_comments($post_id)
{
//set the validation rules
$rules['name'] = 'required';
$rules['email'] = 'required';
$rules['comment'] = 'required';
// here we will need a captcha check like ... $rules['captcha'] =
'required|callback__check_captcha';

// perform validation check
$this->validation->set_rules($rules);

if ($this->validation->run() == FALSE)
{
// if validation fales don't insert comments to DB, direct to blog
entry with errors
$this->load->view('front/blog_entry');
}
else
{
// if validation success insert comments direct to blog entry
$comment = $this->Blog->insertcomm($_POST);

// retrieve entry data and display
$entry_data = $this->Blog->getpost($post_id);
$this->load->view('front/blog_entry', $entry_data);

// retrieve comments and display
$entry_comments = $this->Blog->getcomments($post_id)
$this->load->view('front/comment_view', $entry_comments);
}
}

}

?>

the view is such that when one clicks on it, it take the reader to a post page where he or she can add comments;
#2

[eluser]thinkigniter[/eluser]
Whats the problem?
#3

[eluser]Yash[/eluser]
ebot just make a structure.

What is your aim just let me know that.

Don't paste huge code without any sense.




Theme © iAndrew 2016 - Forum software by © MyBB