• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create a Blog in 20 Minutes codeigniter 2.0.3

#1
[eluser]Unknown[/eluser]
hi guys i just post code of blog:

xxxx\codeigniter\application\controllers\blog.php
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']);


}
}

xxxx\codeigniter\application\view\blog_view.php

Code:
<html>
<head>

<title><?php echo $title?></title>

</head>

<body>

<h1>&lt;?php echo $heading?&gt;</h1>


&lt;?php   foreach($query->result() as $row):?&gt;
<h3>&lt;?php echo $row->title; ?&gt;</h3>
<p>&lt;?php echo $row->body; ?&gt;</p>

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

xxxx\codeigniter\application\view\comment_view.php

Code:
&lt;html&gt;
&lt;head&gt;

&lt;title&gt;&lt;?php echo $title?&gt;&lt;/title&gt;

&lt;/head&gt;

&lt;body&gt;

<h1>&lt;?php echo $heading?&gt;</h1>
&lt;?php if($query->num_rows() > 0): ?&gt;
&lt;?php   foreach($query->result() as $row):?&gt;
<h3>&lt;?php echo $row->body; ?&gt;</h3>
<p>&lt;?php echo $row->author; ?&gt;</p>


<hr>
&lt;?php>
&lt;?php endforeach;?&gt;
&lt;?php endif;?&gt;
<p>&lt;?php echo anchor('blog','Back to Blog');?&gt;</p>
&lt;?php echo form_open('blog/comment_insert');?&gt;

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

<p>&lt;textarea name="body" rows="10"&gt;&lt;/textarea></p>
<p> Name &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;


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.