Inheritance: extends Hasty\Controller
Example #1
0
 public function getAction()
 {
     \Auth::check();
     if (!($fid = intval($_GET['id']))) {
         $errors[] = "Не задан id файла";
     }
     try {
         $file = new File($fid);
         if ($file->userId != $_SESSION['uid']) {
             $errors[] = "Файл не найден";
         } else {
             $filePath = FILE_STORAGE_PATH . $this->getHashedFileName($file);
             header("Pragma: public");
             header("Expires: 0");
             header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
             header("Cache-Control: private", false);
             // нужен для некоторых браузеров
             header("Content-Type: application/force-download");
             header("Content-Disposition: attachment; filename=\"" . $file->name . "\";");
             header("Content-Transfer-Encoding: binary");
             header("Content-Length: " . filesize($filePath));
             readfile("{$filePath}");
             exit;
         }
     } catch (\Exception\ModelNotLoad $e) {
         $errors[] = "Файл не найден";
     } catch (\Exception $e) {
         $errors[] = "Ошибка загрузки файла";
     }
     $this->show('files', $this->getVarsArray($errors));
 }
if ($cfg->ACTIVE_DB) {
    $f3->set('DB', DBHandler::instance()->get($cfg->ACTIVE_DB));
} else {
    $f3->error(500, 'Sorry, but there is no active DB setup.');
}
///////////////
//  frontend //
///////////////
$f3->route(array('GET /', 'GET /@page', 'GET /payloads', 'GET /page/@page'), 'Controller\\Payload->getList');
// view single
$f3->route(array('GET /payload/@id'), 'Controller\\Payload->viewSingle');
$f3->route(array('GET /payload/search'), 'Controller\\Payload->search_frontend');
///////////////
//  backend  //
///////////////
if (\Controller\Auth::isLoggedIn()) {
    // general CRUD operations
    $f3->route('GET|POST /cnc/@module', 'Controller\\Backend->getList');
    $f3->route('GET|POST /cnc/@module/@page', 'Controller\\Backend->getList');
    $f3->route('GET|POST /cnc/@module/@action/@id', 'Controller\\Backend->@action');
    // some method reroutes
    $f3->route('GET /cnc/@module/create', 'Controller\\Backend->getSingle');
    $f3->route('POST /cnc/@module/create', 'Controller\\Backend->post');
    $f3->route('GET /cnc/@module/edit/@id', 'Controller\\Backend->getSingle');
    $f3->route('POST /cnc/@module/edit/@id', 'Controller\\Backend->post');
    $f3->route('GET /cnc/@module/view/@id', 'Controller\\Backend->viewSingle');
    $f3->route('POST /cnc/@module/view/@id', 'Controller\\Backend->viewSingle');
    //Search
    $f3->route('GET /cnc/@module/search', 'Controller\\Backend->getSearchResults');
    $f3->route('POST /cnc/@module/search', 'Controller\\Backend->getSearchResults');
    $f3->route('GET /cnc', 'Controller\\Dashboard->main');