diff --git a/app/controllers/ExampleController.php b/app/controllers/ExampleController.php index dbafc2b..45a6d8c 100644 --- a/app/controllers/ExampleController.php +++ b/app/controllers/ExampleController.php @@ -3,12 +3,8 @@ class ExampleController extends Controller{ public function index(){ - echo 'example'; - - // TODO: - // - set view - // - process POST variables - // ... + $this->view->title = 'Example title'; + $this->view->render('example.phtml'); } public function subpage(){ diff --git a/app/views/layouts/default.phtml b/app/views/layouts/default.phtml new file mode 100644 index 0000000..6479b79 --- /dev/null +++ b/app/views/layouts/default.phtml @@ -0,0 +1,20 @@ + + + + + + <?php echo $this->title ?> + + + +
+ {HEADER} +
+ + content(); ?> + + + + diff --git a/app/views/templates/example.phtml b/app/views/templates/example.phtml new file mode 100644 index 0000000..b5d2471 --- /dev/null +++ b/app/views/templates/example.phtml @@ -0,0 +1 @@ +Example template diff --git a/app/views/templates/loading.css b/app/views/templates/loading.css deleted file mode 100644 index 228c2c0..0000000 --- a/app/views/templates/loading.css +++ /dev/null @@ -1,20 +0,0 @@ -.loader { - border: 16px solid #f3f3f3; - border-radius: 50%; - border-top: 16px solid #3498db; - width: 120px; - height: 120px; - -webkit-animation: spin 2s linear infinite; /* Safari */ - animation: spin 2s linear infinite; -} - -/* Safari */ -@-webkit-keyframes spin { - 0% { -webkit-transform: rotate(0deg); } - 100% { -webkit-transform: rotate(360deg); } -} - -@keyframes spin { - 0% { transform: rotate(0deg); } - 100% { transform: rotate(360deg); } -} \ No newline at end of file diff --git a/library/ApiController.php b/library/ApiController.php index 822bd70..8606280 100644 --- a/library/ApiController.php +++ b/library/ApiController.php @@ -1,12 +1,11 @@ authenticated = false; - $input = file_get_contents('php://input'); + if(empty($input)){ $this->input = NULL; }else{ diff --git a/library/Controller.php b/library/Controller.php index c1d00b4..e1b82fb 100644 --- a/library/Controller.php +++ b/library/Controller.php @@ -1,5 +1,9 @@ view = new View(); + } } diff --git a/library/View.php b/library/View.php new file mode 100644 index 0000000..833860b --- /dev/null +++ b/library/View.php @@ -0,0 +1,63 @@ +_layoutEnabled = false; + } + + public function enableLayout(){ + $this->_layoutEnabled = false; + } + + public function setLayout($layout){ + $this->_layout = $layout; + } + + public function disableView(){ + $this->_viewEnabled = false; + } + + public function __set($key, $value){ + $this->_data[$key] = $value; + } + + public function __get($key){ + if(array_key_exists($key, $this->_data)){ + return $this->_data[$key]; + } + + return null; + } + + public function content(){ + return $this->_content; + } + + public function render($template){ + if($template && $this->_viewEnabled){ + $this->_fetchContent($template); + } + + if($this->_layoutEnabled){ + include('../app/views/layouts/' . $this->_layout . '.phtml'); + } else { + echo $this->_content; + } + } + + protected function _fetchContent($template){ + ob_start(); + + include('../app/views/templates/' . $template); + + $this->_content = ob_get_clean(); + } +} diff --git a/public/css/loading.css b/public/css/loading.css index 6c58598..228c2c0 100644 --- a/public/css/loading.css +++ b/public/css/loading.css @@ -1,19 +1,20 @@ .loader { - border: 16px solid #f3f3f3; - border-radius: 50%; - border-top: 16px solid rgb(101, 30, 122);; - width: 100%; - height: 100%; - -webkit-animation: spin 2s linear infinite; /* Safari */ - animation: spin 2s linear infinite; + border: 16px solid #f3f3f3; + border-radius: 50%; + border-top: 16px solid #3498db; + width: 120px; + height: 120px; + -webkit-animation: spin 2s linear infinite; /* Safari */ + animation: spin 2s linear infinite; } +/* Safari */ @-webkit-keyframes spin { - 0% { -webkit-transform: rotate(0deg); } - 100% { -webkit-transform: rotate(360deg); } + 0% { -webkit-transform: rotate(0deg); } + 100% { -webkit-transform: rotate(360deg); } } @keyframes spin { - 0% { transform: rotate(0deg); } - 100% { transform: rotate(360deg); } + 0% { transform: rotate(0deg); } + 100% { transform: rotate(360deg); } } \ No newline at end of file