<?php if(!empty($therapist)){
foreach($therapist as $ther){
?>
<div class="col-md-4 col-sm-6 portfolio-item">
<a href="#portfolioModal1" class="portfolio-link" data-toggle="modal">
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<i class="fa fa-plus fa-3x"></i>
</div>
</div>
<img src="img/portfolio/roundicons.png" class="img-responsive" alt="">
</a>
<div class="portfolio-caption">
<a href="<?= BASE_URL; ?>therapist/<?= $ther->therapist_username; ?>">
<img src="<?= imageshelper::one_image($ther->therapist_folder); ?>" style="border-radius:50%; border:3px solid #FFF">
</a>
<h4><?= $ther->therapist_name; ?>.</h4>
<p class="text-muted"><?= $ther->therapist_region .", ".$ther->therapist_city; ?></p>
</div>
</div>
<?php } ?>
<?php } ?>
$f3->set('therapist', $this->model("therapist")->find(["therapist_name<>?",""],["limit" => 3, "order" => "therapist_id DESC"]));
/*=========================================================================
* This is are my routes
*==========================================================================
*/
// frontend routes
$f3->route('GET /', 'Homepage->home');
// booking frontend
$f3->route('POST /booking', 'Client_bookings->post_search');
/*=========================================================================
* This is my base controller
*==========================================================================
*/
class BaseController {
protected $db;
protected $csrftoken;
function __construct(){
$f3=Base::instance();
$this->db = new DB\SQL($f3->get('db'), $f3->get('mysql_user'), $f3->get('mysql_password'));
$session = new DB\SQL\Session($this->db);
$this->csrftoken = $session->csrf();
}
public function model($table, $prefix = true){
if($prefix){
return new DB\SQL\Mapper($this->db, TABLE_PREFIX . $table);
} else {
return new DB\SQL\Mapper($this->db, $table);
}
}
protected function library($lib){
require_once APP_LIB . $lib . ".php";
}
/*=========================================================================
* This is my Homepage controller
*==========================================================================
*/
class Homepage extends BaseController {
function __construct() {
parent::__construct();
}
public function home($f3) {
$f3->set('csrftoken', $this->csrftoken);
$f3->set('SESSION.csrftoken',$this->csrftoken);
$f3->set('therapist', $this->model("therapist")->find(["therapist_name<>?",""],["limit" => 3, "order" => "therapist_id DESC"]));
$this->library("imageshelper");
$f3->set('imagehelper', new Imageshelper());
echo View::instance()->render('app/views/frontend/home/main.phtml');
}
/*=========================================================================
* This is my main.phtml render view.
*==========================================================================
*/
<?php require(APP_PATH . "app/views/includes/header.phtml");?>
///
/// if I remove this, the stored token is correct.
///
<!-- Portfolio Grid Section -->
<section id="therapist" class="bg-light-gray">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading">Therapists</h2>
<h3 class="section-subheading text-muted">Latest Therapist Members.</h3>
</div>
</div>
<div class="row">
<?php if(!empty($therapist)){
foreach($therapist as $ther){
?>
<div class="col-md-4 col-sm-6 portfolio-item">
<a href="#portfolioModal1" class="portfolio-link" data-toggle="modal">
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<i class="fa fa-plus fa-3x"></i>
</div>
</div>
<img src="img/portfolio/roundicons.png" class="img-responsive" alt="">
</a>
<div class="portfolio-caption">
<a href="<?= BASE_URL; ?>therapist/<?= $ther->therapist_username; ?>
">
<img src="<?= $imagehelper::one_image($ther->therapist_folder); ?>" style="border-radius:50%; border:3px solid #FFF">
</a>
<h4><?= $ther->therapist_name; ?>.</h4>
<p class="text-muted"><?= $ther->therapist_region .", ".$ther->therapist_city; ?></p>
</div>
</div>
<?php } ?>
<?php } ?>
</div>
</div>
</section>
<!-- Test form submission -->
<section style="margin-top:200px" >
<?php
echo "<form method='POST' action='".BASE_URL."booking'>
<input type='hidden' name='token' value='".$csrftoken."'>
<input type='submit' name='submit'>
</form>";
?>
</section>
<?php require(APP_PATH . "app/views/includes/scripts.phtml") ?>
<?php require(APP_PATH . "app/views/includes/footer.phtml") ?>
/*=========================================================================
* This is my receiving post controller
*==========================================================================
*/
class Client_bookings extends BaseController {
function __construct() {
parent::__construct();
}
/**
* post_search
* Post method for booking search
* @param object $f3 fatfree object
*/
public function post_search($f3) {
#validate submission and save
if ($f3->get('POST.token') == $f3->get('SESSION.csrftoken')) {
# should go here ///////////////////
# error
# function d is just for dumping the data
} else {
d($f3->get('POST.token'),false);
d($f3->get('SESSION.csrftoken')
);
$f3->reroute('/');
}
}
<?php
class Imageshelper {
/**
* for thumbnails
* @param type $directory
*/
public static function one_image($folder, $echo = true){
$directory = realpath(APP_PATH . "user_uploads/" . $folder);
$handle = opendir($directory);
$htm = "";
$get = 1;
$ctr = 0;
while($file = readdir($handle)){
if($file !== '.' && $file !== '..' && $get == 1 && strpos($file, "thumb_") > -1){
if($echo){
echo BASE_URL . "user_uploads/$folder/" . $file;
} else {
return BASE_URL . "user_uploads/$folder/" . $file;
}
$get = 2;
$ctr++;
}
}
# no image was found
if($ctr == 0){
if($echo){
echo BASE_URL . "user_uploads/default-user.png";
} else {
return BASE_URL . "user_uploads/default-user.png";
}
}
}