Permalink
Browse files

Using forward in 404

  • Loading branch information...
1 parent 32dd2db commit 553cc929cc89674380ebb0514222b48bfa998c1d Phalcon committed Nov 2, 2012
View
@@ -5,33 +5,22 @@ username = "root"
password = "secret"
name = "phalcon_site"
-
[app]
-; Cache
-cache.cacheDir = "/app/var/cache/"
-cache.lifetime = 86400
-;cache.host = "localhost"
-;cache.port = 11211
-
; Paths
path.controllers = "/app/controllers/"
path.models = "/app/models/"
path.views = "/app/views/"
path.library = "/app/library/"
; Other
-baseUri = "/"
-timezone = "US/Eastern"
-debug = 1
+baseUri = "/phalconphp/"
; CDN
css.local = true
css.font_sans = "http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800"
css.font_rosario = "http://fonts.googleapis.com/css?family=Rosario"
css.site = "css/style.css"
-css.fork = "css/gh-fork-ribbon.css"
-css.fork_ie = "css/gh-fork-ribbon.ie.css"
js.local = true
js.gs = "javascript/gs.js"
@@ -46,5 +46,6 @@ public function subscribeAction()
public function show404Action()
{
$this->response->setHeader(404, 'Not Found');
+ $this->view->pick('404/404');
}
}
@@ -37,7 +37,7 @@ class Bootstrap
/**
* Constructor
- *
+ *
* @param $di
*/
public function __construct($di)
@@ -47,7 +47,7 @@ public function __construct($di)
/**
* Runs the application performing all initializations
- *
+ *
* @param $options
*
* @return mixed
@@ -58,7 +58,6 @@ public function run($options)
'config',
'loader',
'environment',
- 'timezone',
'flash',
'url',
'dispatcher',
@@ -68,13 +67,12 @@ public function run($options)
'database',
'session',
'cache',
- 'debug',
);
foreach ($loaders as $service)
{
- $function = 'init' . ucfirst($service);
+ $function = 'init' . $service;
$this->$function($options);
}
@@ -139,44 +137,8 @@ protected function initLoader($options = array())
*/
protected function initEnvironment($options = array())
{
- $config = $this->_di->get('config');
-
- $debug = (isset($config->app->debug)) ?
- (bool) $config->app->debug :
- false;
-
- if ($debug)
- {
- ini_set('display_errors', true);
- error_reporting(E_ALL);
- }
- else
- {
- ini_set('display_errors', false);
-// error_reporting( -1 );
- }
-
set_error_handler(array('\Ph\Error', 'normal'));
set_exception_handler(array('\Ph\Error', 'exception'));
- register_shutdown_function(array('\Ph\Error', 'shutdown'));
- }
-
- /**
- * Initializes the timezone
- *
- * @param array $options
- */
- protected function initTimezone($options = array())
- {
- $config = $this->_di->get('config');
-
- $timezone = (isset($config->app->timezone)) ?
- $config->app->timezone :
- 'US/Eastern';
-
- date_default_timezone_set($timezone);
-
- $this->_di->set('timezone_default', $timezone);
}
/**
@@ -252,12 +214,11 @@ function($event, $dispatcher, $exception)
{
case PhDispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case PhDispatcher::EXCEPTION_ACTION_NOT_FOUND:
-
- // Get the 404 page
- $page = file_get_contents(ROOT_PATH . '/app/views/404/404.html');
- $page = str_replace('[ERROR]', $exception->getMessage(), $page);
-
- echo $page;
+ $dispatcher->forward(array(
+ 'controller' => 'index',
+ 'action' => 'show404'
+ ));
+ return false;
}
}
);
@@ -378,49 +339,22 @@ protected function initDatabase($options = array())
{
$config = $this->_di->get('config');
$logger = $this->_di->get('logger');
- $debug = (isset($config->app->debug)) ?
- (bool) $config->app->debug :
- false;
$this->_di->set(
'db',
- function() use ($debug, $config, $logger)
+ function() use ($config, $logger)
{
- if ($debug)
- {
- $eventsManager = new PhEventsManager();
-
- // Listen all the database events
- $eventsManager->attach(
- 'db',
- function($event, $connection) use ($logger) {
- if ($event->getType() == 'beforeQuery') {
- $logger->log(
- $connection->getSQLStatement(),
- PhLogger::INFO
- );
- }
- }
- );
- }
-
$params = array(
"host" => $config->database->host,
"username" => $config->database->username,
"password" => $config->database->password,
"dbname" => $config->database->name,
);
- $conn = new PhMysql($params);
-
- if ($debug)
- {
- // Assign the eventsManager to the db adapter instance
- $conn->setEventsManager($eventsManager);
- }
+ $connection = new PhMysql($params);
- return $conn;
+ return $connection;
}
);
@@ -495,21 +429,4 @@ function() use ($config)
}
- /**
- * Initializes the debugging functions
- *
- * @param array $options
- */
- protected function initDebug($options = array())
- {
- $config = $this->_di->get('config');
- $debug = (isset($config->app->debug)) ?
- (bool) $config->app->debug :
- false;
-
- if ($debug)
- {
- require_once ROOT_PATH . '/app/library/Ph/Debug.php';
- }
- }
}
View
@@ -1,104 +0,0 @@
-<?php
-/**
- * Debug.php
- * Debug
- *
- * Offers shortcuts to functions for easier debugging
- *
- * @author Nikos Dimopoulos <nikos@niden.net>
- * @since 2012-11-01
- * @category Library
- */
-
-if (!function_exists('vd'))
-{
- /**
- * var_dump()
- */
- function vd($string)
- {
- var_dump($string);
- }
-}
-
-if (!function_exists('pr'))
-{
- /**
- * print_r($string, $return)
- */
- function pr($string, $return = FALSE)
- {
- if ($return)
- {
- return print_r($string, TRUE);
- }
- else
- {
- print_r($string);
- }
- }
-}
-
-if (!function_exists('vdd'))
-{
- /**
- * var_dump() + die()
- */
- function vdd($string)
- {
- var_dump($string);
- exit();
- }
-}
-
-if (!function_exists('prd'))
-{
- /**
- * print_r($string, $return) + die()
- */
- function prd($string, $return = FALSE)
- {
- if ($return)
- {
- return print_r($string, TRUE);
- }
- else
- {
- print_r($string);
- }
- exit();
- }
-}
-
-if (!function_exists('gcm'))
-{
- /**
- * get_class_methods($class)
- */
- function gcm($class)
- {
- return get_class_methods($class);
- }
-}
-
-if (!function_exists('e'))
-{
- /**
- * echo($string)
- */
- function e($string)
- {
- print($string);
- }
-}
-
-if (!function_exists('d'))
-{
- /**
- * die($string)
- */
- function d($string = NULL)
- {
- die($string);
- }
-}
View
@@ -1,4 +1,5 @@
<?php
+
/**
* \Ph\Error.php
* Error
@@ -8,7 +9,6 @@
* @author Nikos Dimopoulos <nikos@niden.net>
* @since 7/22/12
* @category Library
- * @license MIT - https://github.com/NDN/phalcon-angular-harryhogfootball/blob/master/LICENSE
*
*/
@@ -71,16 +71,14 @@ protected static function logError($type, $message, $file, $line, $trace = '')
$di = Di::getDefault();
$template = "[%s] %s (File: %s Line: [%s])";
if ($trace) {
- $template . PHP_EOL . $trace;
- }
+ $template . PHP_EOL . $trace;
+ }
$logMessage = sprintf($template, $type, $message, $file, $line);
if ($di->has('logger')) {
-
$logger = $di->get('logger');
if ($logger) {
-
$logger->error($logMessage);
} else {
throw new PhException($logMessage);
View
@@ -1 +0,0 @@
-
Oops, something went wrong.

0 comments on commit 553cc92

Please sign in to comment.