<?php
//routes/backend/post.php

$f3->route('GET /backend/post', function($f3){
    if($f3->get('SESSION.userID')){
        require('controllers/backend/post/get.php');
        get($f3);
    }else{
        $f3->reroute('/login');
    }
});

$f3->route('POST /backend/post', function($f3){
    if($f3->get('SESSION.userID')){
        require('controllers/backend/post/create.php');
        create($f3);
    }else{
        $f3->reroute('/login');
    }
});

 

<?php 
//controllers/backend/post/create.php

function create($f3){
    if($f3->get('SESSION.role') != 'visitor'){
        $title = $f3->get('POST.title');
        $content = $f3->get('POST.content');
        $category = $f3->get('POST.category');
        $thumb = $f3->get('POST.thumb');
        $date = $f3->get('POST.date');
        $video = $f3->get('POST.video');
        $userID = $f3->get('SESSION.userID');
    
        $post = new DB\SQL\Mapper($f3->get('DB'),'posts');

        $post->id = uniqid();
        $post->title = $title;
        $post->content = $content;
        $post->category = $category;
        $post->thumb = $thumb;
        $post->postDate = $date;
        $post->video = $video;
        $post->userID = $userID;
        $post->save();
    }
    
    $f3->reroute('/backend/post');
}

 

<!--views/backend/post.html-->

<script src="<?php echo $BASE ?>/public/scripts/backend/video.js"></script>
<script src="<?php echo $BASE ?>/public/scripts/ckeditor/ckeditor.js"></script>
<link href="<?php echo $BASE ?>/public/styles/backend/post.css" rel="stylesheet"></link>

<?php include('views/backend/partials/header.html') ?>

<section class='Main region'>
    <div class='sidebar'>
        <?php include('views/backend/partials/menu.html') ?>
    </div>

    <div class='content'>
        <form action='<?php echo $BASE ?>/backend/post' method='post'>
            <div class='editor'>
                <input type='text' name='title' required placeholder='ចំណងជើង' />
                <textarea name='content' id='editor'></textarea>
            </div>
            <div class='wrapper'>
                <select name='category'>
                    <option>ជាតិ</option>
                    <option>អន្តរជាតិ</option>
                    <option>ជំនួញ</option>
                </select>

                <input type='text' name='thumb' placeholder='តំណរភ្ជាប់​រូប' required />
                <input type='datetime-local' name='date' required />
                <input type='hidden' name='video' value='' />
                <input type='submit' value='ចុះ​ផ្សាយ' />
            </div>
        </form>

        <div class='video'>
            <select name='type'>
                <option>YouTube</option>
                <option>YTPlaylist</option>
                <option>Facebook</option>
            </select>
            <input type='text' name='id' required placeholder='ID' />

            <select name='ending'>
               <option>Yes</option>
               <option>No</option> 
            </select>

            <input type='submit' value='បញ្ចូល​វីដេអូ' onClick='genJson()' />
        </div>

        <table class='viddata'></table>
    </div>

    <script src="<?php echo $BASE ?>/public/scripts/ckeditor/config.js"></script>

</section>

<?php include('views/backend/partials/footer.html') ?>

 

https://github.com/Sokhavuth/PHP-REST-API

http://khmerweb.epizy.com/media/