[eluser]Unknown[/eluser]
Good evening!
I've the spent the better part of today - in between episodes of "The Office" - figuring out how to get MySql to auto insert a date into my blog and my comments. I've read several other posts and tried several techniques to no avail. With the exception of a CSS sheet and some minor styling, the documents are exactly like the video tutorials. Can someone please show me how to fix this? Any help would be greatly appreciated.
This is what I have:
blog.php file
Code:
<?php
class Blog extends Controller {
function Blog()
{
parent::Controller();
$this->load->scaffolding('entries');
$this->load->helper('url');
$this->load->helper('form');
}
function index()
{
$data['title'] = "This is my title";
$data['heading'] = "This is my heading";
$data['query'] = $this->db->get('entries');
$this->load->view('blog_view', $data);
}
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']);
}
}
?>
comment_view.php
Code:
<h1><?=$heading?></h1>
<?php if ($query->num_rows() > 0):?>
<?php foreach($query->result() as $row): ?>
<p><?=$row->body?></p>
<p><?=$row->author?></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>
blog_view.php
Code:
<h1><?=$heading?></h1>
<?php foreach($query->result() as $row): ?>
<h2><?=$row->date?></h2>
<h3><?=$row->title?></h3>
<p><?=$row->body?></p>
<p><?=anchor('blog/comments/'.$row->id, 'Comments');?></p>
<hr>
<?php endforeach; ?>