Built a rudimentary blog for the sample site.
This commit is contained in:
parent
cab6641a96
commit
13edbb5215
6 changed files with 112 additions and 0 deletions
|
@ -0,0 +1,13 @@
|
|||
[site]
|
||||
disabled = false ; Change to 'true' to take a site down and display a down for maintenance message
|
||||
|
||||
[module]
|
||||
default = posts ; Default module to be loaded when no module is specified
|
||||
template = index ; Main template (wrapper if you will) Typically 'index', but you can name it whatever (sans extension)
|
||||
session = true ; Whether or not to use PHP sessions
|
||||
|
||||
[database]
|
||||
hostname = localhost
|
||||
username = username
|
||||
password = password
|
||||
database = pickles_blog
|
37
sample-site/models/Post.php
Normal file
37
sample-site/models/Post.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Post Model
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* Licensed under the GNU General Public License Version 3
|
||||
* Redistribution of these files must retain the above copyright notice.
|
||||
*
|
||||
* @package PICKLES
|
||||
* @subpackage Sample Site
|
||||
* @author Josh Sherman <josh@phpwithpickles.org>
|
||||
* @copyright Copyright 2007-2010, Gravity Boulevard, LLC
|
||||
* @license http://www.gnu.org/licenses/gpl.html GPL v3
|
||||
* @link http://phpwithpickles.org
|
||||
*/
|
||||
class Post extends Model
|
||||
{
|
||||
/**
|
||||
* Table Name
|
||||
*
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'pickles_posts';
|
||||
|
||||
/**
|
||||
* Columns to Order By
|
||||
*
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $order_by = 'posted_at DESC';
|
||||
}
|
||||
|
||||
?>
|
13
sample-site/modules/posts.php
Normal file
13
sample-site/modules/posts.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
class posts extends Module
|
||||
{
|
||||
public function __default()
|
||||
{
|
||||
$post = new Post(true); // You pass true to tell it to pull everything, this can be modified to support pagination
|
||||
|
||||
return array('posts' => $post->records);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
12
sample-site/schema/pickles_posts.sql
Normal file
12
sample-site/schema/pickles_posts.sql
Normal file
|
@ -0,0 +1,12 @@
|
|||
--
|
||||
-- Table structure for table `posts`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `pickles_posts` (
|
||||
`id` int(1) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`body` text COLLATE utf8_unicode_ci NOT NULL,
|
||||
`posted_at` datetime NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Sample Blog Posts Table for PICKLES' AUTO_INCREMENT=1 ;
|
||||
|
14
sample-site/templates/index.phtml
Normal file
14
sample-site/templates/index.phtml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Sample PICKLES Site</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>PICKLES Blog</h1>
|
||||
<h2>Super simple example of PICKLES in action</h2>
|
||||
<?php
|
||||
// Loads the module's template
|
||||
require_once $template;
|
||||
?>
|
||||
</body>
|
||||
</html>
|
23
sample-site/templates/posts.phtml
Normal file
23
sample-site/templates/posts.phtml
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
// This sanity check could have been in the module and different variables
|
||||
// passed to the template based of if there are any posts
|
||||
if (count($module['posts']) == 0)
|
||||
{
|
||||
echo 'No posts to display';
|
||||
}
|
||||
else
|
||||
{
|
||||
// Loops through the posts and displays them
|
||||
foreach ($module['posts'] as $post)
|
||||
{
|
||||
// Nested templates are supported (since it's just PHP) so if you wanted
|
||||
// to, you could abstract the next block into a another file
|
||||
echo '<h3>' . $post['title'] . '</h3>';
|
||||
echo $post['body'] . '<br /><br />';
|
||||
echo 'Posted at ' . date('g:ia on m/d/Y');
|
||||
echo '<hr />';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue