Go to application>config>database.php
Change name of the database, username and the password.
Create a
Controller : post.php
Model : postmodel.php
View : postview.php
post.php
========
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Post extends CI_Controller {
public function posts(){
$this->load->database();
$this->load->model('Postmodel');
$posts=$this->Postmodel->get_posts();
$view_params['posts']=$posts;
$view_params['mega_title']="Posts";
$this->load->view('postview',$view_params);
}
}
postmodel.php
=============
<?php
class Postmodel extends CI_Model {
function __construct()
{
// Call the Model constructor parent::__construct();
parent::__construct();
}
function get_posts()
{
$query = $this->db->get('posts');
return $query->result();
}
}
postview.php
============
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title><?php echo $mega_title ?></title>
</head>
<body>
<table>
<tr>
<td>Title</td>
<td>Content</td>
</tr>
<?php foreach ($posts as $post): ?>
<tr>
<td><?php echo $post->postTitle ?></td>
<td><?php echo $post->postBody ?></td>
</tr>
<?php endforeach; ?>
</body>
</html>
Change name of the database, username and the password.
Create a
Controller : post.php
Model : postmodel.php
View : postview.php
post.php
========
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Post extends CI_Controller {
public function posts(){
$this->load->database();
$this->load->model('Postmodel');
$posts=$this->Postmodel->get_posts();
$view_params['posts']=$posts;
$view_params['mega_title']="Posts";
$this->load->view('postview',$view_params);
}
}
postmodel.php
=============
<?php
class Postmodel extends CI_Model {
function __construct()
{
// Call the Model constructor parent::__construct();
parent::__construct();
}
function get_posts()
{
$query = $this->db->get('posts');
return $query->result();
}
}
postview.php
============
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title><?php echo $mega_title ?></title>
</head>
<body>
<table>
<tr>
<td>Title</td>
<td>Content</td>
</tr>
<?php foreach ($posts as $post): ?>
<tr>
<td><?php echo $post->postTitle ?></td>
<td><?php echo $post->postBody ?></td>
</tr>
<?php endforeach; ?>
</body>
</html>
No comments:
Post a Comment