<?php
//routes/admin.php
$f3->route('GET /admin', function($f3){
    if($f3->get('SESSION.email')){
        require_once('setting.php');

        $f3->mset([
            'appName'=>$setting['siteTitle'], 
            'title'=>'ទំព័រ​ការផ្សាយ', 
            'date'=>$setting['date'],
            'message'=>$setting['message']
        ]);

        $view = new View;
        echo $view->render('views/admin/index.php');
    }else{
        require_once('controllers/login.php');
        login($f3);
    }
});

require('routes/admin/post.php');

 

<?php
//routes/admin/post.php
$f3->route('POST /admin/post', function($f3){
    require('controllers/posts/insert.php');
    insert($f3);
});

 

<?php
//controllers/posts/insert.php
function insert($f3){
    $collection = $f3->get('DB')->posts;

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

    $collection->insertOne($post);
}

 

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

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