[eluser]fernandoch[/eluser]
Hello, here is the code for the blog tutorial. This version is without models. Look some posts below for the version with models.
application\controllers\blog.php
Code:
<?php
class Blog extends CI_Controller {
function Blog()
{
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
}
function index()
{
$data['title']= "My Blog Title";
$data['heading']= "My Blog 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']);
}
}
?>
application\views\blog_view.php
Code:
<html>
<head>
<title><?php echo $title?></title>
</head>
<body>
<h1><?php echo $heading?></h1>
<?php foreach($query->result() as $row):?>
<h3><? echo $row->title; ?></h3>
<p><? echo $row->body; ?></p>
<p><?=anchor('blog/comments/'.$row->id, 'Comments');?></p>
<hr>
<?php endforeach;?>
</body>
</html>
application\views\comment_view.php
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):?>
<p><? echo $row->body; ?></p>
<p><? echo $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>
</body>
</html>
Look at the next post for database and configuration files.