Exemplo n.º 1
0
 /** Get page by request path
  * @return \System\Page|bool
  */
 public function create_response(array $attrs = null)
 {
     $args = array();
     $params = array();
     $response = false;
     if (is_null($attrs)) {
         $domain = \System\Router::get_domain($this->host);
         if ($domain) {
             $path = \System\Router::get_path($domain, $this->path, $args, $params);
             if ($path) {
                 $path['request'] = $this;
                 $this->args = $args;
                 $this->params = $params;
                 $response = \System\Http\Response::from_request($this, $path);
             }
         }
     } else {
         $response = \System\Http\Response::from_request($this, $attrs);
     }
     return $response;
 }
Exemplo n.º 2
0
 /**
  * @access core.read
  */
 public function exportAction($request)
 {
     $invoice = $this->repo('Invoice')->find($request->query->get('id'));
     if (!$invoice) {
         $this->flash('error', $this->t('invoiceDoesntExists'));
         return $this->redirect('Invoice', 'Invoice', 'index');
     }
     $view = $this->repo('Invoice')->getControllerNameByType($invoice);
     $html = $this->get('templating.engine')->render($view . '.PDF', ['products' => $this->repo('Product')->findAllByInvoice($invoice->getId()), 'invoice' => $invoice, 'type' => $request->get('original') == 1 ? $this->t('invoiceOriginal') : $this->t('invoiceCopy')]);
     if ($request->get('type') == 'pdf') {
         $response = new Response();
         $response->headers->setDisposition('attachment', $invoice->getHeadline() . ' - ' . str_replace('/', '-', $invoice->getNumber()) . ' (' . ($request->get('original') == 1 ? $this->t('invoiceOriginal') : $this->t('invoiceCopy')) . ').pdf');
         $response->headers->set('Content-Type', 'application/pdf');
         try {
             // Remote Images
             define('DOMPDF_ENABLE_REMOTE', true);
             define('DOMPDF_ENABLE_AUTOLOAD', false);
             require_once BASEPATH . '/vendor/dompdf/dompdf/dompdf_config.inc.php';
             $dompdf = new \DOMPDF();
             $dompdf->load_html($html);
             $dompdf->render();
             $response->setContent($dompdf->output());
         } catch (\Exception $e) {
             $this->flash('error', 'Wystąpił błąd podczas generowania pliku PDF: "' . $e->getMessage() . '"');
             return $this->redirect('Invoice', 'Invoice', 'index');
         }
         return $response;
     } else {
         return $this->response($html);
     }
 }
Exemplo n.º 3
0
 /** Enqueue redirect. Passing REDIRECT_NOW will exit pwf and redirect immediately. Otherwise according to queue.
  * @param string $url  URL to redirect to
  * @param int    $code HTTP Status code to send
  * @param int    $when When to redirect, one of (\System\Module\Flow::REDIRECT_LATER,\System\Module\Flow::REDIRECT_AFTER_MODULES,\System\Module\Flow::REDIRECT_NOW)
  * @return void
  */
 public function redirect($url, $code = \System\Http\Response::FOUND, $when = self::REDIRECT_AFTER_MODULES)
 {
     $when === self::REDIRECT_IMMEDIATELY && \System\Http\Response::redirect($url, $code);
     $this->redirect[$when] = array("url" => $url, "code" => $code);
 }