Code refactoring, #16
git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@114 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
51
app/Action.php
Normal file
51
app/Action.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage app
|
||||
* @since 2010-02-25
|
||||
* @version SVN: $Id$
|
||||
* @filesource $URL$
|
||||
*/
|
||||
|
||||
abstract class Action
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->extractParams();
|
||||
$this->execute();
|
||||
}
|
||||
|
||||
protected function extractParams()
|
||||
{
|
||||
$params = FrontController::getInstance()->getRouter()->getRoute()->getParams();
|
||||
if ($params) {
|
||||
foreach ($params as $name => $value) {
|
||||
if (is_string($name)) {
|
||||
$this->$name = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract protected function execute();
|
||||
|
||||
/**
|
||||
* Redirect
|
||||
*
|
||||
* @param mixed $url
|
||||
* @param mixed $relative Default to true
|
||||
*/
|
||||
protected function redirect($url = null, $relative = true)
|
||||
{
|
||||
$url = ($url) ? $url : Env::getRequestUri();
|
||||
|
||||
if ($relative) {
|
||||
$url = FrontController::getInstance()->getBaseUrl() . $url;
|
||||
}
|
||||
header('Location: ' . $url);
|
||||
exit();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user