[eluser]Unknown[/eluser]
Hey guys, im new to codeigniter and I'm after creating a blog that can delete specific comments based on unique IDs, I also want each post once submitted to be displayed with a Time/Date stamp, I have been at this for hours on end and im no closer to completing any of the two tasks, some guidance would greatly be appreciated.
Here is the MVC and Database tables:
Controller:
<?php
class Blog extends Controller {
function Blog ()
{
parent::Controller();
$this->load->scaffolding('entries');
$this->load->helper('url');
$this->load->helper('form');
$this->load->helper('date');
}
function index()
{
//$data['title'] = "My Blog Title";
//$data['heading'] = "My Blog Heading";
$data['query'] = $this->db->get('entries');
$this->load->vars($data);
$this->load->view('blog_view');
}
function comments()
{
//$data['title'] = "My Comment Title";
//$data['heading'] = "My Comment Heading";
$this->db->where('entry_id', $this->uri->segment(3));
$data['query'] = $this->db->get('comments');
$this->load->view('comment_view', $data);
}
function comment_insert()
{
$this->db->insert('comments', $_POST);
redirect('blog/comments/'.$_POST['entry_id']);
}
function delete_post($id)
{
$this->db->where('id', $id);
$this->db->delete('comments');
redirect('blog');
}
}
?>
Blog View:
<html>
<head>
<title><?php //echo $title; ?></title>
</head>
<body>
<h1>Class Notes</h1>
<ol>
<?php foreach($query->result() as $row): ?>
<h3><?=$row->class_title?></h3>
<p><?=$row->body?></p>
<p><?=anchor('blog/comments/'.$row->id, 'Comments');?></p>
<hr>
<?php endforeach; ?>
</ol>
</body>
</html>
Comment View:
<html>
<head>
<title><?php //echo $title; ?></title>
</head>
<body>
<h1></h1>
<?php if ($query->num_rows() > 0): ?>
<?php foreach($query->result() as $row): ?>
<p><?=$row->body?></p>
<p>Submitted by: <?=$row->author?></p>
<p>Submitted at:
<?php
?></p>
<p><?=anchor('blog/delete_post', 'Delete');?></p>
<hr>
<?php endforeach; ?>
<?php endif; ?>
<p><?=anchor('blog', 'Back to Blog');?></p>
<?=form_open('blog/comment_insert');?>
<?=form_hidden('entry_id', $this->uri->segment(3));?>
<p><textarea name="body" rows="10"></textarea></p>
<p><input type="text" name="author" /></p>
<p><input type="submit" value="Submit Comment" /></p>
</form>
</body>
</html>
DATABASE TABLES:
Comments {id, entry_id, body, author}
Entries {id, class_title, body}
Any Help on solving one of these problems would be greatly appreciated, as stated before, I am new to Codeigniter, I have followed the tutorials and after hours of attempting, I cannot get the delete function to work or a date/time stamp to be generated on each post.
Thanks for your time
Mitchell