Code:
<?php
class Blog extends CI_Controller {
function Blog(){
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
}
public function index(){
$this->load->database();
$data['title']= "My BloG";
$data['heading']= "My php *Blog*";
$data['query'] = $this->db->get('post'); // post is a table name
$this->load->view('blog_view',$data);
//echo "Hello php World";
}
public function comments()
{
$this->load->database();
$data['title']= "My Comment Title";
$data['heading']= "My Comment heading";
$this->db->where('entry_id', $this->uri->segment(3));
$data['query']= $this->db->get('comment');
$this->load->view('comment_view',$data);
}
function comment_insert()
{
$this->load->database();
$this->db->insert('comment',$_POST);
redirect('blog/comments/',$POST['entry_id']);
}
}
Code:
<html>
<head>
<title><?php echo $title?></title>
</head>
<body>
<h1><?php echo $heading?></h1>
<?php foreach($query->result() as $row):?>
<h3><?php echo $row->title; ?></h3>
<p><?php echo $row->body; ?></p>
<p><?php echo anchor('blog/comments/'.$row->id, 'Comments'); ?></p>
<hr>
<?php>
<?php endforeach;?>
Code:
<html>
<head>
<title><?php echo $title?></title>
</head>
<body>
<h1><?php echo $heading?></h1>
<?php if($query->num_rows() > 0): ?>
<?php foreach($query->result() as $row):?>
<h3><?php echo $row->body; ?></h3>
<p><?php echo $row->author; ?></p>
<hr>
<?php>
<?php endforeach;?>
<?php endif;?>
<p><?php echo anchor('blog','Back to Blog');?></p>
<?php echo form_open('blog/comment_insert');?>
<?php form_hidden('entry_id',$this->uri->segment(3));?>
<p><textarea name="body" rows="10"></textarea></p>
<p> Name <input type="text" name="author"/></p>
<p><input type="submit" value="Submit Comment"/></p>
</form>
</body>
</html>