Created
July 8, 2012 14:36
-
-
Save okaprinarjaya/3071223 to your computer and use it in GitHub Desktop.
Core Class - Controller
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 | |
class Controller { | |
public function renderTemplate($templateName, $data = null, $contentType = 'html') { | |
try { | |
$viewObject = new View(get_called_class(), $contentType); | |
$viewObject->render($templateName, $data); | |
} catch(Exception $e) { | |
echo $e->getMessage(); | |
} | |
} | |
public function setFlashMessage($message,$type) { | |
try { | |
$session = new SessionHandler(); | |
$session->start(); | |
$session->set('message', array('message' => $message, 'type' => $type)); | |
$session->save(); | |
} catch (Exception $e) { | |
echo $e->getMessage(); | |
} | |
} | |
public function redirect($location = null) { | |
$url = ''; | |
/* | |
* Pattern for String passed | |
* String => 'controller/action' | |
*/ | |
if (is_string($location)) { | |
$locationPieces = explode('/',$location); | |
$url = $locationPieces[0].'.php?act='.$locationPieces[1]; | |
} | |
/* | |
* Pattern for Array passed | |
* Array => Array ( | |
* 'controller' => 'controller name' | |
* 'action' => 'action name' | |
* ) | |
*/ | |
if (is_array($location)) { | |
$url = $location['controller'].'.php?act='.$location['action']; | |
} | |
header('Location:'.$url); | |
} | |
public function getAction() { | |
$action = 'index'; | |
if (isset($_GET['act'])) { | |
$action = trim($_GET['act']); | |
} | |
return $action; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment