This repository has been archived on 2025-05-12. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
hack13-blog/app/Controllers/Blog.php
2020-07-27 22:22:06 -04:00

42 lines
No EOL
949 B
PHP

<?php namespace App\Controllers;
use App\Models\BlogModel;
use CodeIgniter\Controller;
class Blog extends Controller
{
public function index()
{
helper('html');
$model = new BlogModel();
$data = [
'blog' => $model->getBlog(),
'title' => 'Blog',
];
echo view('common/header', $data);
echo view('blog/overview', $data);
echo view('common/footer', $data);
}
public function view($slug = null)
{
helper('html');
$model = new BlogModel();
$data['blog'] = $model->getBlog($slug);
if (empty($data['blog']))
{
throw new \CodeIgniter\Exceptions\PageNotFoundException('Cannot find the blog post: '. $slug);
}
$data['data'] = $data['blog']['title'];
echo view('common/header', $data);
echo view('blog/view', $data);
echo view('common/footer', $data);
}
}