/** * Catch the exception and log it, display pretty view * * @param \Exception $e */ public static function exception(\Exception $e) { $config = \Phalcon\DI::getDefault()->getShared('config'); $errors = array('error' => get_class($e) . '[' . $e->getCode() . ']: ' . $e->getMessage(), 'info' => $e->getFile() . '[' . $e->getLine() . ']', 'debug' => "Trace: \n" . $e->getTraceAsString() . "\n"); if ($config->app->env == "development") { // Display debug output $debug = new \Phalcon\Debug(); $debug->onUncaughtException($e); } else { // Display pretty view of the error $di = new \Phalcon\DI\FactoryDefault(); $view = new \Phalcon\Mvc\View\Simple(); $view->setDI($di); $view->setViewsDir(APP_PATH . '/app/frontend/views/'); $view->registerEngines(\Baseapp\Library\Tool::registerEngines($view, $di)); echo $view->render('error', array('i18n' => I18n::instance(), 'config' => $config)); // Log errors to file and send email with errors to admin \Baseapp\Bootstrap::log($errors); } }
/** * Database connection is created based in the parameters defined in the configuration file */ $di->set('db', function () use($config) { $db_config = $config->database[ENVIRONMENT]; return new \Phalcon\Db\Adapter\Pdo\Mysql(array('host' => $db_config->dbhost, 'username' => $db_config->dbusername, 'password' => $db_config->dbpassword, 'dbname' => $db_config->dbname)); }, true); $di->set('acl', function () use($di, $config) { return new Phalcon\Acl\Adapter\Database(array('db' => $di->get('db'), 'roles' => 'roles', 'rolesInherits' => 'roles_inherits', 'resources' => 'resources', 'resourcesAccesses' => 'resources_accesses', 'accessList' => 'access_list')); }, true); $di->set('translate', function () { return new Lininliao\Library\Locale\Translate(SITENAME); }, true); $di->set('simpleView', function () use($di, $config) { $view = new \Phalcon\Mvc\View\Simple(); $view->setDI($di); $view->registerEngines(array('.volt' => function ($view, $di) { $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di); $compiledPath = ROOT . DS . 'cache' . DS . SITENAME . DS . 'volt' . DS; if (!file_exists($compiledPath)) { mkdir($compiledPath, 0777, true); } $volt->setOptions(array('compiledPath' => $compiledPath, 'compiledExtension' => '.cache', 'compiledSeparator' => '%', 'stat' => true, 'compileAlways' => ENVIRONMENT === 'production' ? false : true)); $compiler = $volt->getCompiler(); $compiler->addFunction('_', function ($resolvedArgs, $exprArgs) use($di) { $translate = $di->get('translate'); return $translate->trans($exprArgs, $resolvedArgs); }); return $volt; })); return $view;