Skip to content

Instantly share code, notes, and snippets.

@geggleto
Created February 25, 2015 16:21
Show Gist options
  • Select an option

  • Save geggleto/a7e43db0026b077c669d to your computer and use it in GitHub Desktop.

Select an option

Save geggleto/a7e43db0026b077c669d to your computer and use it in GitHub Desktop.
<?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