| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace KarmaFW\Routing\Controllers;
- use \KarmaFW\WebApp;
- class WebAppController extends AppController
- {
- protected $request_uri = null;
- protected $request_method = null;
- protected $route = null;
- protected $template;
-
- public function __construct($request_uri=null, $request_method=null, $route=null)
- {
- parent::__construct($request_uri, $request_method, $route);
- $this->user_id = session('user_id');
- $this->flash = session('flash');
- $_SESSION['flash'] = []; // ['success' => 'action done !', 'error' => 'an error occured', 'warning' => 'notice ...']
- if (defined('TPL_DIR')) {
- $this->template = WebApp::createTemplate();
- $this->template->assign('user_id', $this->user_id);
- $this->template->assign('flash', $this->flash);
- if (defined('APP_NAME')) {
- $this->template->assign('meta_title', APP_NAME);
- $this->template->assign('meta_description', APP_NAME);
- $this->template->assign('h1', APP_NAME);
- }
- }
- }
- public function getRoute()
- {
- return $this->route;
- }
- public function getRequestMethod()
- {
- return $this->request_method;
- }
- public function getRequestUri()
- {
- return $this->request_uri;
- }
- public function getTemplate()
- {
- return $this->template;
- }
- public function error($http_status, $meta_title=null, $h1=null, $message=null)
- {
- return WebApp::error($http_status, $meta_title, $h1, $message);
- }
- public function error400($title = 'Bad request', $message = '')
- {
- return $this->error(400, $title, $title, $message);
- }
- public function error403($title = 'Forbidden', $message = 'you are not allowed')
- {
- return $this->error(403, $title, $title, $message);
- }
- public function error404($title = 'Page not found', $message = "The page you're looking for doesn't exist")
- {
- return $this->error(404, $title, $title, $message);
- }
- public function error500($title = 'Internal Server Error', $message = 'An error has occured')
- {
- return $this->error(500, $title, $title, $message);
- }
- public function error503($title = 'Service Unavailable', $message = 'The service is unavailable')
- {
- return $this->error(503, $title, $title, $message);
- }
- }
|