Created
February 25, 2015 16:21
-
-
Save geggleto/a7e43db0026b077c669d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace controllers; | |
| /** | |
| * Description of Controller | |
| * | |
| * @author Glenn | |
| */ | |
| class Controller { | |
| protected static $app; | |
| public function __construct($app) { | |
| self::$app = $app; | |
| } | |
| public function redirect($route, $param=array()) { | |
| $app = self::$app; | |
| $url = $app->urlFor($route, $param); | |
| $app->response->redirect($url, 301); | |
| } | |
| public function render($route_name, $param=array(), $return=FALSE) { | |
| $app = self::$app; | |
| if ($return) { | |
| $route = $app->router()->getNamedRoute($route_name); | |
| $route->setParams($param); | |
| ob_start(); | |
| $route->dispatch(); | |
| return ob_get_clean(); | |
| } else { | |
| $app->render($route_name, $param); | |
| } | |
| } | |
| public function authenticate() { | |
| return function () { | |
| $app = \Slim\Slim::getInstance(); | |
| if (empty($app->session->getPein())) { | |
| $app->flash('error', 'Login required'); | |
| $this->redirect("page_login"); | |
| } | |
| }; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment