CodeIgniter Forums

Full Version: Blog Date/Time Stamp & Delete function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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>

&lt;?php foreach($query->result() as $row): ?&gt;

<h3>&lt;?=$row->class_title?&gt;</h3>
<p>&lt;?=$row->body?&gt;</p>

<p>&lt;?=anchor('blog/comments/'.$row->id, 'Comments');?&gt;</p>

<hr>

&lt;?php endforeach; ?&gt;
</ol>

&lt;/body&gt;
&lt;/html&gt;

Comment View:

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;?php //echo $title; ?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<h1></h1>

&lt;?php if ($query->num_rows() > 0): ?&gt;

&lt;?php foreach($query->result() as $row): ?&gt;

<p>&lt;?=$row->body?&gt;</p>
<p>Submitted by: &lt;?=$row->author?&gt;</p>
<p>Submitted at:
&lt;?php
?&gt;</p>

<p>&lt;?=anchor('blog/delete_post', 'Delete');?&gt;</p>

<hr>

&lt;?php endforeach; ?&gt;

&lt;?php endif; ?&gt;

<p>&lt;?=anchor('blog', 'Back to Blog');?&gt;</p>

&lt;?=form_open('blog/comment_insert');?&gt;

&lt;?=form_hidden('entry_id', $this->uri->segment(3));?&gt;

<p>&lt;textarea name="body" rows="10"&gt;&lt;/textarea></p>
<p>&lt;input type="text" name="author" /&gt;&lt;/p>
<p>&lt;input type="submit" value="Submit Comment" /&gt;&lt;/p>

&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;

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

El Forum

[eluser]InsiteFX[/eluser]
Please wrap your code in CODE TAGS!
Code:
// Remove spaces after code!
[code ]
// your code
[/code ]

Code:
-- --------------------------------------------------------
--
-- Database: `blog`
--
-- --------------------------------------------------------

--
-- Table structure for table `categories`
--

CREATE TABLE IF NOT EXISTS `categories` (
  `id`            int(11)            NOT NULL    AUTO_INCREMENT,
  `parent_id`    int(11)            NOT NULL    DEFAULT '0',
  `name`        varchar(255)    NOT NULL    DEFAULT '',
  `short_desc`    varchar(255)    NOT NULL    DEFAULT '',
  `long_desc`    text            NOT NULL,
  `status`        enum('active', 'inactive')    NOT NULL    DEFAULT 'active',
  `sort_order`    int(3)            NOT NULL    DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table `categories`
--

-- --------------------------------------------------------

--
-- Table structure for table `comments`
--

CREATE TABLE IF NOT EXISTS `comments` (
  `id`            int(11)            NOT NULL    AUTO_INCREMENT,
  `post_id`        int(11)            NOT NULL,
  `name`        varchar(255)    NOT NULL,
  `email`        varchar(255)    NOT NULL,
  `body`        varchar(255)    NOT NULL,
  `pub_date`    datetime        NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table `comments`
--


-- --------------------------------------------------------

--
-- Table structure for table `posts`
--

CREATE TABLE IF NOT EXISTS `posts` (
  `id`            int(11)            NOT NULL    AUTO_INCREMENT,
  `user_id`        int(11)            NOT NULL,
  `category_id`    int(11)            NOT NULL,
  `title`        varchar(255)    NOT NULL,
  `tags`        varchar(255)    NOT NULL,
  `status`        enum('draft', 'published')    NOT NULL,
  `body`        text            NOT NULL,
  `pub_date`    datetime        NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table `posts`
--

InsiteFX