<?php
//routes/admin.php

$f3->route('GET /admin', function($f3){
    if($f3->get('SESSION.email')){
        require_once('controllers/admin/index.php');
        index($f3);
    }else{
        $f3->reroute('./login');
    }
});

$f3->route('GET /admin/logout', function($f3){
    $f3->clear('SESSION');
    $f3->reroute('./');
});

$f3->route('GET /admin_post', function($f3){
    if($f3->get('SESSION.email')){
        require_once('controllers/admin/posts/reads.php');
        reads($f3);
    }else{
        $f3->reroute('./login');
    }
});

$f3->route('POST /admin_post', function($f3){
    if($f3->get('SESSION.email')){
        require_once('controllers/admin/posts/create.php');
        create($f3);
    }else{
        $f3->reroute('./login');
    }
});

 

<?php 
//controllers/admin/posts/create.php

function create($f3){
    require('table.php');
    table($f3);

    $id = uniqid();
    $title = addslashes($f3->get('POST.title'));
    $content = addslashes($f3->get('POST.content'));
    $thumb = addslashes($f3->get('POST.thumb'));
    $category = addslashes($f3->get('POST.category'));
    $date = addslashes($f3->get('POST.datetime'));
    $video = addslashes($f3->get('POST.entries'));
    $author = addslashes($f3->get('SESSION.email'));

    $sql = "INSERT INTO posts (id, title, content, thumb, category, date, video, author) 
    VALUES('$id', '$title', '$content', '$thumb', '$category', '$date', '$video', '$author')";

    $f3->get('DB')->exec($sql);

    $f3->reroute('./admin_post');
}

 

GitHub: https://github.com/Sokhavuth/tvp

Heroku: https://khmerweb-tvp.herokuapp.com/