コード例 #1
0
ファイル: ErrorHandler.php プロジェクト: Lavoaster/PVLive
 public static function handle(\Exception $e, \Phalcon\DiInterface $di)
 {
     if ($e instanceof \DF\Exception\NotLoggedIn) {
         // Redirect to login page for not-logged-in users.
         \DF\Flash::addMessage('You must be logged in to access this page!');
         // Set referrer for login redirection.
         $session = \DF\Session::get('referrer_login');
         $session->url = \DF\Url::current($di);
         // Redirect to login page.
         $login_url = $di->get('url')->get('account/login');
         $response = $di->get('response');
         $response->redirect($login_url, 302);
         $response->send();
         return;
     } elseif ($e instanceof \DF\Exception\PermissionDenied) {
         // Bounce back to homepage for permission-denied users.
         \DF\Flash::addMessage('You do not have permission to access this portion of the site.', \DF\Flash::ERROR);
         $home_url = $di->get('url')->get('');
         $response = $di->get('response');
         $response->redirect($home_url, 302);
         $response->send();
         return;
     } elseif ($e instanceof \Phalcon\Mvc\Dispatcher\Exception) {
         // Handle 404 page not found exception
         if ($di->has('view')) {
             $view = $di->get('view');
             $view->disable();
         }
         $view = \DF\Phalcon\View::getView(array());
         $result = $view->getRender('error', 'pagenotfound');
         $response = $di->get('response');
         $response->setStatusCode(404, "Not Found");
         $response->setContent($result);
         $response->send();
         return;
     } elseif ($e instanceof \DF\Exception\Bootstrap) {
         // Bootstrapping error; cannot render template for error display.
         if (DF_APPLICATION_ENV != 'production') {
             self::renderPretty($e, $di);
             return;
         } else {
             $response = $di->get('response');
             $response->setStatusCode(500, "Internal Server Error");
             $exception_msg = "<b>Application core exception: </b>\n<blockquote>" . $e->getMessage() . "</blockquote>" . "\n" . "on line <b>" . $e->getLine() . "</b> of <i>" . $e->getFile() . "</i>";
             $response->setContent($exception_msg);
             $response->send();
             return;
         }
     } else {
         if ($di->has('view')) {
             $view = $di->get('view');
             $view->disable();
         }
         $show_debug = false;
         if ($di->has('acl')) {
             $acl = $di->get('acl');
             if ($acl->isAllowed('administer all')) {
                 $show_debug = true;
             }
         }
         if (DF_APPLICATION_ENV != 'production') {
             $show_debug = true;
         }
         if ($show_debug) {
             self::renderPretty($e, $di);
             return;
         } else {
             $view = \DF\Phalcon\View::getView(array());
             $view->setVar('exception', $e);
             $result = $view->getRender('error', 'general');
             $response = $di->get('response');
             $response->setStatusCode(500, "Internal Server Error");
             $response->setContent($result);
             $response->send();
             return;
         }
     }
 }
コード例 #2
0
ファイル: Controller.php プロジェクト: Lavoaster/PVLive
 protected function storeReferrer($namespace = 'default', $loose = true)
 {
     $session = Session::get('referrer_' . $namespace);
     if (!isset($session->url) || $loose && isset($session->url) && Url::current() != Url::referrer()) {
         $session->url = Url::referrer();
     }
 }
コード例 #3
0
ファイル: Form.php プロジェクト: Lavoaster/PVLive
 /**
  * Render the entire form (or a specified field name).
  *
  * @param null $name The portion of the form to render (leave null for the entire form).
  * @return string The rendered form.
  */
 public function render($name = null)
 {
     if ($name !== null) {
         return $this->_renderField($name, array());
     }
     $form_defaults = array('method' => 'POST', 'action' => \DF\Url::current(), 'class' => 'form-stacked df-form');
     $form_options = (array) $this->options;
     unset($form_options['elements'], $form_options['groups']);
     $form_options = array_merge($form_defaults, $form_options);
     $form_tag = '<form';
     foreach ((array) $form_options as $option_key => $option_value) {
         $form_tag .= ' ' . $option_key . '="' . $option_value . '"';
     }
     $form_tag .= '>';
     $return = '';
     $return .= $form_tag;
     if ($this->options['groups']) {
         foreach ($this->options['groups'] as $group_id => $group_info) {
             if (!empty($group_info['legend'])) {
                 $return .= '<fieldset id="' . $group_id . '">';
                 $return .= '<legend>' . $group_info['legend'] . '</legend>';
                 if ($group_info['description']) {
                     $return .= '<p>' . $group_info['description'] . '</p>';
                 }
             }
             foreach ($group_info['elements'] as $element_key => $element_info) {
                 $return .= $this->_renderField($element_key, $element_info);
             }
             if (!empty($group_info['legend'])) {
                 $return .= '</fieldset>';
             }
         }
     }
     if (!empty($this->options['elements'])) {
         foreach ($this->options['elements'] as $element_key => $element_info) {
             $return .= $this->_renderField($element_key, $element_info);
         }
     }
     $return .= '</form>';
     return $return;
 }