Memcache, refactoring, View helpers, #16
git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@124 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
@ -13,7 +13,7 @@ class ErrorAction extends ViewAction
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Exception
|
||||
* @var ErrorException
|
||||
*/
|
||||
protected $exception;
|
||||
|
||||
@ -36,12 +36,12 @@ class ErrorAction extends ViewAction
|
||||
return '/static/' . $this->template;
|
||||
}
|
||||
|
||||
protected function sendHttpCode($code)
|
||||
protected function sendHttpCode()
|
||||
{
|
||||
if (headers_sent()) {
|
||||
return;
|
||||
}
|
||||
switch ($code) {
|
||||
switch ($this->template) {
|
||||
case 404:
|
||||
header('HTTP/1.0 404 Not Found');
|
||||
break;
|
||||
@ -50,9 +50,40 @@ class ErrorAction extends ViewAction
|
||||
}
|
||||
}
|
||||
|
||||
protected function logError()
|
||||
{
|
||||
if ($this->template = 500) {
|
||||
|
||||
$error = 0;
|
||||
$ex = $this->exception;
|
||||
if ($ex instanceof ErrorException) {
|
||||
$error = $ex->getSeverity();
|
||||
}
|
||||
|
||||
switch ($error) {
|
||||
case E_NOTICE:
|
||||
$error = 'Notice';
|
||||
break;
|
||||
case E_WARNING:
|
||||
$error = 'Warning';
|
||||
break;
|
||||
case E_ERROR:
|
||||
$error = 'Fatal Error';
|
||||
break;
|
||||
default:
|
||||
$error = 'Unknown Error';
|
||||
break;
|
||||
}
|
||||
$message = 'PHP ' . $error . ': ' . $ex->getMessage() . ' in ' . $ex->getFile()
|
||||
. ' on line ' . $ex->getLine();
|
||||
error_log($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function fetch()
|
||||
{
|
||||
$this->sendHTTPCode($this->template);
|
||||
$this->logError();
|
||||
$this->sendHTTPCode();
|
||||
return $this->view->fetch($this->getTemplate());
|
||||
}
|
||||
}
|
@ -32,6 +32,9 @@ class FrontController
|
||||
private function __construct()
|
||||
{
|
||||
ErrorHandler::init();
|
||||
if (DEBUG == true) {
|
||||
Profiler::getInstance()->start();
|
||||
}
|
||||
$this->router = new Router();
|
||||
}
|
||||
|
||||
@ -96,7 +99,6 @@ class FrontController
|
||||
public function execute()
|
||||
{
|
||||
try {
|
||||
|
||||
$request = Env::getRequestUri();
|
||||
$route = $this->getRouter()->route($request);
|
||||
if (!$route) {
|
||||
@ -107,14 +109,16 @@ class FrontController
|
||||
if (!class_exists($action_class)) {
|
||||
throw new GeneralException('Action class "' . $action_class . '" not found.');
|
||||
}
|
||||
|
||||
$action = new $action_class();
|
||||
$layout_class = $route->getLayout();
|
||||
if (!class_exists($layout_class)) {
|
||||
throw new GeneralException('Layout class "' . $layout_class . '" not found.');
|
||||
}
|
||||
$layout = new $layout_class();
|
||||
return $layout->fetch($action);
|
||||
|
||||
$layout = new $layout_class();
|
||||
$html = $layout->fetch($action);
|
||||
return (!DEBUG) ? $html : Profiler::getInstance()->end($html);
|
||||
} catch(Exception $e) {
|
||||
if (DEBUG == true) {
|
||||
return ErrorHandler::showDebug($e);
|
||||
|
66
app/PagerAction.php
Normal file
66
app/PagerAction.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage app
|
||||
* @since 2010-03-07
|
||||
* @version SVN: $Id$
|
||||
* @filesource $URL$
|
||||
*/
|
||||
|
||||
class PagerAction extends ViewAction
|
||||
{
|
||||
public $page;
|
||||
public $last_page;
|
||||
|
||||
//protected $num_rows;
|
||||
|
||||
protected $offset = 0;
|
||||
protected $count = 0;
|
||||
protected $limit;
|
||||
|
||||
public function __construct($count, $limit = 20)
|
||||
{
|
||||
$this->count = $count;
|
||||
$this->limit = $limit;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function execute()
|
||||
{
|
||||
$page = (int) Env::Get('p');
|
||||
$this->last_page = ceil($this->count/$this->limit);
|
||||
$this->page = ($page <= $this->last_page && $page > 0) ? $page : 1;
|
||||
$this->offset = $this->limit * ($this->page - 1);
|
||||
//$this->num_rows = ($this->limit + $this->offset) <= $this->count ? ($this->limit + $this->offset) : $this->count;
|
||||
}
|
||||
|
||||
public function getOffset()
|
||||
{
|
||||
return $this->offset;
|
||||
}
|
||||
|
||||
public function getLimit()
|
||||
{
|
||||
return $this->limit;
|
||||
}
|
||||
|
||||
protected function getTemplate()
|
||||
{
|
||||
$template = ($this->template) ? $this->template : substr(get_class($this), 0, -6/*strlen('Action')*/);
|
||||
return '/actions/' . $template;
|
||||
}
|
||||
|
||||
|
||||
/* public function setNumRows($num_rows)
|
||||
{
|
||||
$this->num_rows = $num_rows;
|
||||
}
|
||||
*/
|
||||
/*function prepare()
|
||||
{
|
||||
$this->templater->assign('page', $this->page);
|
||||
$this->templater->assign('page_max', $this->max_page_num);
|
||||
}*/
|
||||
}
|
Reference in New Issue
Block a user