Blog and Pages are now database driven, woo!
This commit is contained in:
parent
34fe54c20c
commit
1f1cf3b71b
20 changed files with 137 additions and 24 deletions
6
app/.htaccess
Normal file
6
app/.htaccess
Normal file
|
@ -0,0 +1,6 @@
|
|||
<IfModule authz_core_module>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
<IfModule !authz_core_module>
|
||||
Deny from all
|
||||
</IfModule>
|
|
@ -30,9 +30,9 @@ $routes->setAutoRoute(true);
|
|||
|
||||
// We get a performance increase by specifying the default
|
||||
// route since we don't have to scan directories.
|
||||
$routes->get('(:any)', 'Pages::view/$1');
|
||||
$routes->get('blog', 'Blog::index');
|
||||
$routes->get('blog/(:segment)', 'Blog::view/$1');
|
||||
$routes->get('(:any)', 'Pages::view/$1');
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use App\Models\BlogModel;
|
||||
use CodeIgniter\Controller;
|
||||
use CodeIgniter\Services;
|
||||
|
||||
class Blog extends Controller
|
||||
{
|
||||
|
@ -11,7 +12,8 @@ class Blog extends Controller
|
|||
$model = new BlogModel();
|
||||
|
||||
$data = [
|
||||
'blog' => $model->getBlog(),
|
||||
'blog' => $model->orderBy('id', 'DESC')->paginate(5),
|
||||
'pager' => $model->pager,
|
||||
'title' => 'Blog',
|
||||
];
|
||||
|
||||
|
|
|
@ -1,28 +1,38 @@
|
|||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Models\PagesModel;
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
class Pages extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
helper('html');
|
||||
echo view('common/header');
|
||||
echo view('home');
|
||||
echo view('common/footer');
|
||||
}
|
||||
|
||||
public function view($slug = null)
|
||||
{
|
||||
helper('html');
|
||||
public function view($slug = null)
|
||||
{
|
||||
helper('html');
|
||||
$model = new PagesModel();
|
||||
|
||||
if (empty($slug)) {
|
||||
$page = "home";
|
||||
} else {
|
||||
$page = $slug;
|
||||
if (empty($slug))
|
||||
{
|
||||
$data['page'] = $model->getPage('home');
|
||||
}else{
|
||||
$data['page'] = $model->getPage($slug);
|
||||
}
|
||||
|
||||
echo view('common/header');
|
||||
echo view('pages/'.$page);
|
||||
echo view('common/footer');
|
||||
}
|
||||
if (empty($data['page']))
|
||||
{
|
||||
throw new \CodeIgniter\Exceptions\PageNotFoundException('Cannot find the page: '. $slug);
|
||||
}
|
||||
|
||||
$data['data'] = $data['page']['name'];
|
||||
$viewtype = $data['page']['contain'];
|
||||
|
||||
echo view('common/header', $data);
|
||||
if ($viewtype == 1) {
|
||||
echo view('pages/view1', $data);
|
||||
}else{
|
||||
echo view('pages/view2', $data);
|
||||
}
|
||||
echo view('common/footer', $data);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
0
app/Database/Migrations/.gitkeep
Normal file
0
app/Database/Migrations/.gitkeep
Normal file
0
app/Database/Seeds/.gitkeep
Normal file
0
app/Database/Seeds/.gitkeep
Normal file
0
app/Filters/.gitkeep
Normal file
0
app/Filters/.gitkeep
Normal file
0
app/Helpers/.gitkeep
Normal file
0
app/Helpers/.gitkeep
Normal file
0
app/Language/.gitkeep
Normal file
0
app/Language/.gitkeep
Normal file
0
app/Libraries/.gitkeep
Normal file
0
app/Libraries/.gitkeep
Normal file
0
app/Models/.gitkeep
Normal file
0
app/Models/.gitkeep
Normal file
|
@ -1,16 +1,19 @@
|
|||
<?php namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
use CodeIgniter\Services;
|
||||
|
||||
class BlogModel extends Model
|
||||
{
|
||||
protected $table = 'blog';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
public function getBlog($slug = false)
|
||||
{
|
||||
if ($slug === false)
|
||||
{
|
||||
return $this->findAll();
|
||||
return $this->orderBy('id', 'DESC')
|
||||
->findAll();
|
||||
}
|
||||
|
||||
return $this->asArray()
|
||||
|
@ -18,4 +21,10 @@ class BlogModel extends Model
|
|||
->first();
|
||||
}
|
||||
|
||||
public function getBlogs($limit = false, $offset = 0)
|
||||
{
|
||||
return $this->orderBy('id', 'DESC')
|
||||
->findAll($limit, $offset);
|
||||
}
|
||||
|
||||
}
|
21
app/Models/PagesModel.php
Normal file
21
app/Models/PagesModel.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class PagesModel extends Model
|
||||
{
|
||||
protected $table = 'pages';
|
||||
|
||||
public function getPage($slug = false)
|
||||
{
|
||||
if ($slug === false)
|
||||
{
|
||||
return $this->findAll();
|
||||
}
|
||||
|
||||
return $this->asArray()
|
||||
->where(['slug' => $slug])
|
||||
->first();
|
||||
}
|
||||
|
||||
}
|
0
app/ThirdParty/.gitkeep
vendored
Normal file
0
app/ThirdParty/.gitkeep
vendored
Normal file
|
@ -6,15 +6,17 @@
|
|||
|
||||
<?php foreach ($blog as $blog_item): ?>
|
||||
|
||||
<h3><?= esc($blog_item['title']); ?></h3>
|
||||
<h3><?= esc($blog_item['title']); ?></h3> <tt><?= esc($blog_item['published']); ?></tt>
|
||||
|
||||
<div class="main">
|
||||
<?= esc($blog_item['body']); ?>
|
||||
<?php echo(substr($blog_item['body'], 0, 250)).'...'; ?>
|
||||
</div>
|
||||
<p><a href="/blog/<?= esc($blog_item['slug'], 'url'); ?>">View article</a></p>
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?= $pager->simpleLinks() ?>
|
||||
|
||||
<?php else : ?>
|
||||
|
||||
<h3>No News</h3>
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<main role="main">
|
||||
<div class="container">
|
||||
<h1 class="mt-5"><?= esc($blog['title']); ?></h1>
|
||||
<?= esc($blog['body']); ?>
|
||||
<?= esc($blog['body'], 'raw'); ?>
|
||||
<br />
|
||||
<a href="/blog" class="btn btn-secondary">Back To Blog</a>
|
||||
</div>
|
||||
</main>
|
6
app/Views/pages/view1.php
Normal file
6
app/Views/pages/view1.php
Normal file
|
@ -0,0 +1,6 @@
|
|||
<main role="main">
|
||||
<div class="container">
|
||||
<h1 class="mt-5"><?= esc($page['name']); ?></h1>
|
||||
<?= esc($page['body'], 'raw'); ?>
|
||||
</div>
|
||||
</main>
|
1
app/Views/pages/view2.php
Normal file
1
app/Views/pages/view2.php
Normal file
|
@ -0,0 +1 @@
|
|||
<?= esc($page['body'], 'raw'); ?>
|
48
public/.htaccess
Normal file
48
public/.htaccess
Normal file
|
@ -0,0 +1,48 @@
|
|||
# Disable directory browsing
|
||||
Options All -Indexes
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# Rewrite engine
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
# Turning on the rewrite engine is necessary for the following rules and features.
|
||||
# FollowSymLinks must be enabled for this to work.
|
||||
<IfModule mod_rewrite.c>
|
||||
Options +FollowSymlinks
|
||||
RewriteEngine On
|
||||
|
||||
# If you installed CodeIgniter in a subfolder, you will need to
|
||||
# change the following line to match the subfolder you need.
|
||||
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
|
||||
# RewriteBase /
|
||||
|
||||
# Redirect Trailing Slashes...
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule ^(.*)/$ /$1 [L,R=301]
|
||||
|
||||
# Rewrite "www.example.com -> example.com"
|
||||
RewriteCond %{HTTPS} !=on
|
||||
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
|
||||
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
|
||||
|
||||
# Checks to see if the user is attempting to access a valid file,
|
||||
# such as an image or css document, if this isn't true it sends the
|
||||
# request to the front controller, index.php
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]
|
||||
|
||||
# Ensure Authorization header is passed along
|
||||
RewriteCond %{HTTP:Authorization} .
|
||||
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
|
||||
</IfModule>
|
||||
|
||||
<IfModule !mod_rewrite.c>
|
||||
# If we don't have mod_rewrite installed, all 404's
|
||||
# can be sent to index.php, and everything works as normal.
|
||||
ErrorDocument 404 index.php
|
||||
</IfModule>
|
||||
|
||||
# Disable server signature start
|
||||
ServerSignature Off
|
||||
# Disable server signature end
|
6
writable/.htaccess
Executable file
6
writable/.htaccess
Executable file
|
@ -0,0 +1,6 @@
|
|||
<IfModule authz_core_module>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
<IfModule !authz_core_module>
|
||||
Deny from all
|
||||
</IfModule>
|
Reference in a new issue