Created
March 14, 2009 13:54
-
-
Save henrikbjorn/79073 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* Abstract class to do some preconfiguration for all controllers | |
* extending this one. | |
* | |
* @package BaseApp | |
*/ | |
abstract class Base_Controller extends Controller | |
{ | |
protected $Session; | |
protected $View; | |
protected $ViewTemplate; | |
protected $Render = TRUE; | |
protected $Layout = 'default'; | |
protected $Allow = array(); | |
protected $Deny; | |
protected $Role; | |
protected $Auth; | |
/** | |
* Does some standard app specific loading | |
**/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
//Loads the session module | |
$this->Session = Session::instance(); | |
$this->Auth = Auth::instance(); | |
$this->Auth->auto_login(); | |
//Simple auth checking | |
if ($this->Allow != '*' && !in_array(Router::$method, $this->Allow)) { | |
if (!$this->Auth->logged_in()) { | |
url::redirect($this->Session->get('requested_uri')); | |
} elseif (!$this->Auth->logged_in($this->Role)) { | |
url::redirect('/page/access/denied'); | |
} | |
} | |
//generate controller path for views | |
$this->View = new stdClass; | |
//Hook | |
Event::add('system.post_controller', array($this, '__render')); | |
} | |
/** | |
* Handles template render etc | |
*/ | |
public function __render() | |
{ | |
if ($this->Render) { | |
//Layout and template | |
$this->Layout = new View('layouts/' . $this->Layout); | |
$this->ViewTemplate = ($this->ViewTemplate) ? $this->ViewTemplate : Router::$controller . '/' . Router::$method; | |
$View = new View($this->ViewTemplate); | |
foreach ($this->View as $var => $value) { | |
$View->$var = $value; | |
} | |
$this->Layout->_Session = $View->_Session = $this->Session; | |
$this->Layout->content = $View; | |
$this->Layout->render(TRUE); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment