Created
November 15, 2012 21:22
-
-
Save weatheredwatcher/4081359 to your computer and use it in GitHub Desktop.
How to Build a Blog in 15 Minutes (using Codeigniter)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
class Blog extends CI_Controller { | |
function __construct() | |
{ | |
parent::__construct(); | |
} | |
function index() | |
{ | |
$this->load->model('Blog_model', 'blog'); | |
$data["results"] = $this->blog->get_last_ten_entries(); | |
$this->load->view('blog_view', $data); | |
} | |
function add() | |
{ | |
$this->load->view('blog_new'); | |
} | |
function insert_page(){ | |
$this->load->model('Blog_model', 'blog'); | |
$this->blog->insert_entry(); | |
echo('<h2>Blog entry added..thanks!</h2>'); | |
} | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
/* End of file blog_model.php */ | |
/* Location: ./application/models/blog_model.php */ | |
class Blog_model extends CI_Model { | |
function __construct() | |
{ | |
parent::__construct(); | |
} | |
function get_last_ten_entries() | |
{ | |
$this->db->order_by('timestamp', 'desc'); | |
$query = $this->db->get('blog', 10); | |
return $query->result(); | |
} | |
function insert_entry() | |
{ | |
$this->title = $this->input->post('title'); | |
$this->entry = $this->input->post('entry'); | |
$this->db->insert('blog', $this); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
?><!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Welcome to CodeIgniter</title> | |
<style type="text/css"> | |
::selection{ background-color: #E13300; color: white; } | |
::moz-selection{ background-color: #E13300; color: white; } | |
::webkit-selection{ background-color: #E13300; color: white; } | |
body { | |
background-color: #fff; | |
margin: 40px; | |
font: 13px/20px normal Helvetica, Arial, sans-serif; | |
color: #4F5155; | |
} | |
a { | |
color: #003399; | |
background-color: transparent; | |
font-weight: normal; | |
} | |
h1 { | |
color: #444; | |
background-color: transparent; | |
border-bottom: 1px solid #D0D0D0; | |
font-size: 19px; | |
font-weight: normal; | |
margin: 0 0 14px 0; | |
padding: 14px 15px 10px 15px; | |
} | |
code { | |
font-family: Consolas, Monaco, Courier New, Courier, monospace; | |
font-size: 12px; | |
background-color: #f9f9f9; | |
border: 1px solid #D0D0D0; | |
color: #002166; | |
display: block; | |
margin: 14px 0 14px 0; | |
padding: 12px 10px 12px 10px; | |
} | |
#body{ | |
margin: 0 15px 0 15px; | |
} | |
p.footer{ | |
text-align: right; | |
font-size: 11px; | |
border-top: 1px solid #D0D0D0; | |
line-height: 32px; | |
padding: 0 10px 0 10px; | |
margin: 20px 0 0 0; | |
} | |
#container{ | |
margin: 10px; | |
border: 1px solid #D0D0D0; | |
-webkit-box-shadow: 0 0 8px #D0D0D0; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="container"> | |
<h1>Welcome to Our Blog</h1> | |
<div id="body"> | |
Enter a new blog entry | |
<!-- Form --> | |
<div class="in forms"> | |
<form id="entry_form" name="entry_form" method="post" action="insert_page"> | |
<p><strong>TITLE</strong><br> | |
<input name="title" class="box" type="text"></p> | |
<p><strong>STORY</strong><br> | |
<textarea name="entry" rows="5" cols="30" class="box"></textarea></p> | |
<p><input name="submit" id="submit" tabindex="5" class="com_btn" value="SUBMIT" type="submit"></p> | |
</form> | |
</div> | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
?><!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Welcome to CodeIgniter</title> | |
<style type="text/css"> | |
::selection{ background-color: #E13300; color: white; } | |
::moz-selection{ background-color: #E13300; color: white; } | |
::webkit-selection{ background-color: #E13300; color: white; } | |
body { | |
background-color: #fff; | |
margin: 40px; | |
font: 13px/20px normal Helvetica, Arial, sans-serif; | |
color: #4F5155; | |
} | |
a { | |
color: #003399; | |
background-color: transparent; | |
font-weight: normal; | |
} | |
h1 { | |
color: #444; | |
background-color: transparent; | |
border-bottom: 1px solid #D0D0D0; | |
font-size: 19px; | |
font-weight: normal; | |
margin: 0 0 14px 0; | |
padding: 14px 15px 10px 15px; | |
} | |
code { | |
font-family: Consolas, Monaco, Courier New, Courier, monospace; | |
font-size: 12px; | |
background-color: #f9f9f9; | |
border: 1px solid #D0D0D0; | |
color: #002166; | |
display: block; | |
margin: 14px 0 14px 0; | |
padding: 12px 10px 12px 10px; | |
} | |
#body{ | |
margin: 0 15px 0 15px; | |
} | |
p.footer{ | |
text-align: right; | |
font-size: 11px; | |
border-top: 1px solid #D0D0D0; | |
line-height: 32px; | |
padding: 0 10px 0 10px; | |
margin: 20px 0 0 0; | |
} | |
#container{ | |
margin: 10px; | |
border: 1px solid #D0D0D0; | |
-webkit-box-shadow: 0 0 8px #D0D0D0; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="container"> | |
<h1>Welcome to Our Blog</h1> | |
<div id="body"> | |
<?php foreach($results as $entry): ?> | |
<h3><?=$entry->title; ?></h3> | |
<?=$entry->entry; ?> | |
<?php endforeach; ?> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sssss