Project Details
Website/App: Microblog Framework – udemy project
Main Language: PHP OOP
Other Languages: Bootstrap/CSS, jQuery, SQL/PDO, HTML
Frontend: Blog Content, Forms
- Blog-Index
- Post Preview
- Categories
- Hashtags
- Blog-Posts:
- Comment Form
- Bulletin Board Code
- Login Page
- Authentication Service
Backend: Blog Administration
- update, delete & edit/create new posts
- Blog Post Editor
- Blogpost Admin Table (Update, Delete)
Level: Intermediate
Purpose: Fast Creation Of Lightweight Mini Blog CMS
State: Uncomplete
Project: Udemy Course Project
Summary
I developed this micro CMS framework during a udemy course in object-oriented programming in PHP. The goal was to build a framework with predefined methods that allow building weblogs quickly, using predefined methods. Please note that this project is only an exercise that wasn’t built with user experience in mind but focusses solely on functionality. Nevertheless, I think it’s a good example to showcase my skills in OOP. The Core Elements of the App are the container class that initializes all the other main classes, the controller classes which render the blog components (like the blog-posts preview, the blog posts, the categories, etc.), and the repository classes whose job is to take care of database queries. In the following article, I will describe these elements in detail.
Frontend
Repository Classes
The repositories contain generic database queries as methods that will be used to render dynamic content like blog posts, categories, etc..
//Here we have an example of the category repository
<?php
namespace app\blog;
use PDO;
class catrepo
{
private $pdo;
public function __construct(PDO $pdo)
{
$this->pdo = $pdo;
}
//Selects all entries from the categories table - can be used build a category widget
function cat()
{
$sql = "SELECT * FROM categories ORDER BY kname ASC";
$abfrage = $this->pdo->query($sql);
$res = $abfrage->fetchAll(PDO::FETCH_CLASS, "app\\blog\\catmodel");
return $res;
}
//Selects all category descriptions - can be used in a posts preview displayed by category
function catBeschreibung(){
$kID = (int)$_GET["category"];
$sql = "SELECT * FROM categories
WHERE kID = :kID" ;
$abfrage = $this->pdo->prepare($sql);
$abfrage->bindParam(":kID", $kID);
$abfrage->execute();
$abfrage->setFetchMode(PDO::FETCH_CLASS, "app\\blog\\catmodel");
$catBeschreibung = $abfrage->fetch(PDO::FETCH_CLASS);
return $catBeschreibung;
}
function catName(){
$kID = (int)$posts["kFID"];
$sql = "SELECT * FROM categories
WHERE kID = :kID" ;
$abfrage = $this->pdo->prepare($sql);
$abfrage->bindParam(":kID", $kID);
$abfrage->execute();
$abfrage->setFetchMode(PDO::FETCH_CLASS, "app\\blog\\catmodel");
$catName = $abfrage->fetch(PDO::FETCH_CLASS);
return $catName;
}
}
?>
Object-Oriented Programming in PHP | figure 1.0: catrepo.php
Controller Classes
The purpose of the controller classes is to make use of their corresponding repository methods to render dynamic site components, like the category widget for example.
<?php
namespace app\blog;
use app\core\abstractcontroller;
class catcontroller extends abstractcontroller
{
public function __construct(catrepo $catrepo, postrepo $postreposit)
{
$this->catrepo = $catrepo;
$this->postreposit = $postreposit;
}
public function category()
{
$res = $this->catrepo->cat();
foreach($res as $kategorie){
$this->render("blog/category", [
"kategorie" => $kategorie
]);
}
}
public function formSelectCategory()
{
$res = $this->catrepo->cat();
foreach($res as $eCat){
$this->render("blog/editor/selectcategory", [
"eCat" => $eCat
]);
}
}
public function categorydesc()
{
$catBeschreibung = $this->catrepo->catBeschreibung();
$this->render("blog/categorydescription", [
"catBeschreibung" => $catBeschreibung
]);
}
}
?>
figure 1.1: example for a controller – catcontroller.php