<?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/reads.php
function reads($f3){
require_once('setting.php');
$posts = $f3->get('DB')->exec('SELECT * FROM posts ORDER BY date DESC LIMIT ?', $setting['adminPostLimit']);
$f3->mset([
'appName'=>$setting['siteTitle'],
'title'=>'ទំព័រការផ្សាយ',
'date'=>$setting['date'],
'items'=>$posts,
'message'=>'ចំនួនការផ្សាយសរុបៈ '.count($posts),
'route'=>'post'
]);
$view = new View;
echo $view->render('ui/admin/post.php');
}
<link href="ui/styles/admin/listing.css" rel="stylesheet"></link>
<script src='ui/scripts/admin/paginate.js'></script>
<section class='List region'>
<div class='info'><?php echo $message ?></div>
<div class='wrapper'>
<?php foreach ($items as $item){ ?>
<div class='item'>
<div class='thumb'>
<a href='./<?php echo $route ?>/<?php echo $item["id"] ?>'>
<?php if($item["thumb"]){ ?>
<img src="<?php echo $item['thumb'] ?>" />
<?php }else{ ?>
<img src='ui/images/no-image.png' />
<?php } ?>
<?php if($item["video"]){ ?>
<img class="playicon" src="ui/images/play.png" />
<?php } ?>
</a>
</div>
<div class='title'>
<a href='./<?php echo $route ?>/<?php echo $item["id"] ?>'>
<?php echo $item["title"] ?>
</a>
<a href='./<?php echo $route ?>/<?php echo $item["id"] ?>'>
<div><?php echo $item["author"] ?></div>
</a>
</div>
<div class='edit'>
<a href='./admin_<?php echo $route ?>_edit/<?php echo $item["id"] ?>'>
<img src="ui/images/edit.png" />
</a>
<a href='./admin_<?php echo $route ?>_delete/<?php echo $item["id"] ?>'>
<img src="ui/images/delete.png" />
</a>
</div>
</div>
<?php } ?>
</div>
<div class='paginate'>
<a onClick='paginate("<?php $route ?>")'><img src='ui/images/load-more.png' /></div></a>
</div>
</section>
GitHub: https://github.com/Sokhavuth/tvp