/** * Instantiates the correct view class, hands it its data, and uses it to render the view output. * * @param string $view View to use for rendering * @param string $layout Layout to use * @return \Cake\Network\Response A response object containing the rendered view. * @link http://book.cakephp.org/3.0/en/controllers.html#rendering-a-view */ public function render($view = null, $layout = null) { $builder = $this->viewBuilder(); if (!$builder->templatePath()) { $builder->templatePath($this->_viewPath()); } if (!empty($this->request->params['bare'])) { $builder->autoLayout(false); } $builder->className($this->viewClass); $this->autoRender = false; $event = $this->dispatchEvent('Controller.beforeRender'); if ($event->result instanceof Response) { return $event->result; } if ($event->isStopped()) { return $this->response; } if ($builder->template() === null && isset($this->request->params['action'])) { $builder->template($this->request->params['action']); } $this->View = $this->createView(); $this->response->body($this->View->render($view, $layout)); return $this->response; }
/** * Render a Pdf view. * * @param string $view The view being rendered. * @param string $layout The layout being rendered. * @return string The rendered view. */ public function render($view = null, $layout = null) { $content = parent::render($view, $layout); if ($this->response->type() == 'text/html') { return $content; } if ($this->renderer() == null) { $this->response->type('html'); return $content; } if (isset($this->pdfConfig['download']) && $this->pdfConfig['download'] === true) { $this->response->download($this->getFilename()); } $this->Blocks->set('content', $this->renderer()->output($content)); return $this->Blocks->get('content'); }
/** * Render the cell. * * @param string|null $template Custom template name to render. If not provided (null), the last * value will be used. This value is automatically set by `CellTrait::cell()`. * @return string The rendered cell. * @throws \Cake\View\Exception\MissingCellViewException When a MissingTemplateException is raised during rendering. */ public function render($template = null) { $cache = []; if ($this->_cache) { $cache = $this->_cacheConfig($this->action); } $render = function () use($template) { if ($template !== null && strpos($template, '/') === false && strpos($template, '.') === false) { $template = Inflector::underscore($template); } if ($template === null) { $template = $this->template; } $builder = $this->viewBuilder(); $builder->layout(false); $builder->template($template); $className = substr(strrchr(get_class($this), "\\"), 1); $name = substr($className, 0, -4); $builder->templatePath('Cell' . DS . $name); try { $reflect = new ReflectionMethod($this, $this->action); $reflect->invokeArgs($this, $this->args); } catch (ReflectionException $e) { throw new BadMethodCallException(sprintf('Class %s does not have a "%s" method.', get_class($this), $this->action)); } $this->View = $this->createView(); try { return $this->View->render($template); } catch (MissingTemplateException $e) { throw new MissingCellViewException(['file' => $template, 'name' => $name]); } }; if ($cache) { return Cache::remember($cache['key'], $render, $cache['config']); } return $render(); }
private function _testEnabled($method = 'GET') { $request = new Request(); $request->env('REQUEST_METHOD', $method); $request->here = '/pages/home'; $response = new Response(); $View = new View($request, $response); $View->loadHelper('ViewMemcached.ViewMemcached', ['cacheConfig' => TEST_CACHE_CONFIG]); $View->viewPath = 'Pages'; $View->set('test', 'value'); $View->render('home', 'default'); return $View->ViewMemcached->enabled(); }
/** * Render controller view. * * @param string|null $view * @param string|null $layout * @return null|string */ public function render($view = null, $layout = null) { $this->_setupMetaData(); $view = $this->_getFormView($view); return parent::render($view, $layout); }
public function render($view = null, $layout = null) { // !IMPORTANT: Render view before initializing CakeTcpdf, because TCPDF sets the encoding to ASCII $content = parent::render($view, $layout); $pdfParams = $this->get('pdf'); $this->engine()->SetTitle($pdfParams['title']); $this->engine()->SetSubject($pdfParams['subject']); $this->engine()->SetKeywords($pdfParams['keywords']); Configure::write('debug', false); $this->engine()->AddPage(); $this->engine()->writeHTML($content, true, 0, true, 0); $filename = isset($pdfParams['filename']) ? $pdfParams['filename'] : 'document.pdf'; $output = isset($pdfParams['output']) ? $pdfParams['output'] : 'S'; switch (strtoupper($output)) { case "D": // force download return $this->engine()->Output($filename, 'D'); case "I": // send to browser return $this->engine()->Output('', 'I'); case "F": // save to disk return $this->engine()->Output(TMP . $filename, 'F'); case "FD": // save to disk and force download return $this->engine()->Output(TMP . $filename, 'FD'); case "S": default: // send as application/pdf response $this->response->type('pdf'); $this->response->header('Content-Disposition: inline; filename="' . $filename . '"'); return $this->engine()->Output('', 'S'); } }
/** * Render the cell. * * @param string|null $template Custom template name to render. If not provided (null), the last * value will be used. This value is automatically set by `CellTrait::cell()`. * @return string The rendered cell. * @throws \Cake\View\Exception\MissingCellViewException When a MissingTemplateException is raised during rendering. */ public function render($template = null) { if ($template !== null && strpos($template, '/') === false && strpos($template, '.') === false) { $template = Inflector::underscore($template); } if ($template === null) { $template = $this->template; } $builder = $this->viewBuilder(); $builder->layout(false); $builder->template($template); $cache = []; if ($this->_cache) { $cache = $this->_cacheConfig($template); } $this->View = $this->createView(); $render = function () use($template) { $className = substr(strrchr(get_class($this), "\\"), 1); $name = substr($className, 0, -4); $this->View->templatePath('Cell' . DS . $name); try { return $this->View->render($template); } catch (MissingTemplateException $e) { throw new MissingCellViewException(['file' => $template, 'name' => $name]); } }; if ($cache) { return $this->View->cache(function () use($render) { echo $render(); }, $cache); } return $render(); }
/** * Render method * * @param string $view The view being rendered. * @param string $layout The layout being rendered. * @return string The rendered view. */ public function render($view = null, $layout = null) { $content = parent::render($view, $layout); if ($this->response->type() == 'text/html') { return $content; } $this->Blocks->set('content', $this->output()); $this->response->download($this->getFilename()); return $this->Blocks->get('content'); }
/** * Render the cell. * * @param string|null $template Custom template name to render. If not provided (null), the last * value will be used. This value is automatically set by `CellTrait::cell()`. * @return string The rendered cell. * @throws \Cake\View\Exception\MissingCellViewException When a MissingTemplateException is raised during rendering. */ public function render($template = null) { $cache = []; if ($this->_cache) { $cache = $this->_cacheConfig($this->action); } $render = function () use ($template) { try { $reflect = new ReflectionMethod($this, $this->action); $reflect->invokeArgs($this, $this->args); } catch (ReflectionException $e) { throw new BadMethodCallException(sprintf( 'Class %s does not have a "%s" method.', get_class($this), $this->action )); } $builder = $this->viewBuilder(); if ($template !== null && strpos($template, '/') === false && strpos($template, '.') === false ) { $template = Inflector::underscore($template); } if ($template === null) { $template = $builder->template() ?: $this->template; } $builder->layout(false) ->template($template); $className = get_class($this); $namePrefix = '\View\Cell\\'; $name = substr($className, strpos($className, $namePrefix) + strlen($namePrefix)); $name = substr($name, 0, -4); if (!$builder->templatePath()) { $builder->templatePath('Cell' . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $name)); } $this->View = $this->createView(); try { return $this->View->render($template); } catch (MissingTemplateException $e) { throw new MissingCellViewException(['file' => $template, 'name' => $name]); } }; if ($cache) { return Cache::remember($cache['key'], $render, $cache['config']); } return $render(); }
/** * [render description] * @param [type] $action [description] * @param [type] $layout [description] * @param [type] $file [description] * @return [type] [description] */ public function render($action = null, $layout = null, $file = null) { $content = parent::render($action, false, $file); if ($this->response->type() == 'text/html') { return $content; } $content = $this->__output(); $this->Blocks->set('content', $content); $this->response->download($this->getFilename()); return $this->Blocks->get('content'); }
/** * Render view template or return serialized data. * * ### Special parameters * `_serialize` To convert a set of view variables into a serialized form. * Its value can be a string for single variable name or array for multiple * names. If true all view variables will be serialized. If unset normal * view template will be rendered. * * @param string|null $view The view being rendered. * @param string|null $layout The layout being rendered. * @return string|null The rendered view. */ public function render($view = null, $layout = null) { $serialize = false; if (isset($this->viewVars['_serialize'])) { $serialize = $this->viewVars['_serialize']; } if ($serialize !== false) { return $this->_serialize($serialize); } elseif ($view !== false && $this->_getViewFileName($view)) { return parent::render($view, false); } }
public function render($view = null, $layout = null) { $this->viewPath = 'Sitemap'; $this->subDir = 'xml'; if ($view === null) { $type = $this->get('type', SitemapComponent::TYPE_SITEMAP); $view = 'Sitemap.' . $type; } //$sitemap = $this->get('locations'); //if (!$sitemap) { // throw new NotFoundException('Sitemap not initalized'); //} return parent::render($view, false); }
/** * Renders view for given template file and layout. * * @param null $view * @param null $layout * @return string|void */ public function render($view = null, $layout = null) { if (is_null($view) && in_array($this->request->param('action'), ['edit', 'add'])) { $searchPaths = App::path('Template', $this->plugin); $formViewFile = $this->__findViewByRequest($searchPaths); if (!$formViewFile) { $view = 'form'; } } if ($this->Union->isAdmin()) { $this->Assets->widget('.jsToggle', 'UnionFieldToggle', ['csrfToken' => $this->request->cookie('csrfToken')]); } return parent::render($view, $layout); }
/** * Render the cell. * * @param string $template Custom template name to render. If not provided (null), the last * value will be used. This value is automatically set by `CellTrait::cell()`. * @return void */ public function render($template = null) { if ($template !== null) { $template = Inflector::underscore($template); } if (empty($template)) { $template = $this->template; } $this->View = $this->createView(); $this->View->layout = false; $className = explode('\\', get_class($this)); $className = array_pop($className); $this->View->subDir = 'Cell' . DS . substr($className, 0, strpos($className, 'Cell')); return $this->View->render($template); }
public function get_for_parent($parent, $page) { $comments = $this->Comments->find()->where(['Comments.object_id' => $parent])->limit(__MAX_COMMENTS_LISTED)->page($page)->order('Comments.created DESC')->contain(['Authors' => ['fields' => ['id', 'first_name', 'last_name', 'avatar']]]); // Reorder the Comments by creation order // (even though we got them by descending order) $collection = new Collection($comments); $comments = $collection->sortBy('Comment.created'); $view = new View($this->request, $this->response, null); $view->layout = 'ajax'; // layout to use or false to disable $view->set('comments', $comments->toArray()); $data['html'] = $view->render('Social.Comments/get_for_parent'); $this->layout = 'ajax'; $this->set('data', $data); $this->render('/Shared/json/data'); }
/** * Renders an AJAX view. * The rendered content will be part of the JSON response object and * can be accessed via response.content in JavaScript. * * If an error has been set, the rendering will be skipped. * * @param string $view The view being rendered. * @param string $layout The layout being rendered. * @return string The rendered view. */ public function render($view = null, $layout = null) { $response = ['error' => null, 'content' => null]; if (!empty($this->viewVars['error'])) { $view = false; } if ($view !== false && !isset($this->viewVars['_redirect']) && $this->_getViewFileName($view)) { $response['content'] = parent::render($view, $layout); } if (isset($this->viewVars['_serialize'])) { $response = $this->_serialize($response, $this->viewVars['_serialize']); } $result = json_encode($response); if (json_last_error() !== JSON_ERROR_NONE) { return json_encode(['error' => json_last_error_msg()]); } return $result; }
/** * Render the gizmo. * * @param string $template Custom template name to render. If not provided (null), the last * value will be used. This value is automatically set by `GizmoTrait::gizmo()`. * @return void * @throws \Cake\View\Exception\MissingGizmoViewException When a MissingViewException is raised during rendering. */ public function render($template = null) { if ($template !== null && strpos($template, '/') === false) { $template = Inflector::underscore($template); } if ($template === null) { $template = $this->template; } $this->View = null; $this->getView(); $this->View->layout = false; $className = explode('\\', get_class($this)); $className = array_pop($className); $name = substr($className, 0, strpos($className, 'Gizmo')); $this->View->subDir = 'Gizmo' . DS . $name; try { return $this->View->render($template); } catch (MissingViewException $e) { throw new MissingGizmoViewException(['file' => $template, 'name' => $name]); } }
/** * Render a JSON view. * * ### Special parameters * `_serialize` To convert a set of view variables into a JSON response. * Its value can be a string for single variable name or array for multiple names. * You can omit the`_serialize` parameter, and use a normal view + layout as well. * `_jsonp` Enables JSONP support and wraps response in callback function provided in query string. * - Setting it to true enables the default query string parameter "callback". * - Setting it to a string value, uses the provided query string parameter for finding the * JSONP callback name. * * @param string|null $view The view being rendered. * @param string|null $layout The layout being rendered. * @return string|null The rendered view. */ public function render($view = null, $layout = null) { $return = null; if (isset($this->viewVars['_serialize'])) { $return = $this->_serialize($this->viewVars['_serialize']); } elseif ($view !== false && $this->_getViewFileName($view)) { $return = parent::render($view, false); } if (!empty($this->viewVars['_jsonp'])) { $jsonpParam = $this->viewVars['_jsonp']; if ($this->viewVars['_jsonp'] === true) { $jsonpParam = 'callback'; } if (isset($this->request->query[$jsonpParam])) { $return = sprintf('%s(%s)', h($this->request->query[$jsonpParam]), $return); $this->response->type('js'); } } return $return; }
/** * Generate PDF * @param $id */ public function pdf($id = null) { $row = $this->Orders->findById($id)->contain(["Users", "Statuses", "Operations", "Accessories", "Images"])->first(); if (!$row) { throw new InternalErrorException("Chyba pri nacitani objednavky", 500); } $view = new View($this->request, $this->response, null); $view->layout = "ajax"; $view->set("row", $row); $html = $view->render("Orders/pdf"); $pdf = new \DOMPDF(); $pdf->load_html(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8')); $pdf->set_paper('a4', 'portrait'); $pdf->render(); $pdf->stream("order-" . $id . ".pdf", array("Attachment" => 0)); }
/** * {@inheritDoc} * * Overrides Cake's view rendering method. Allows to "render" objects. * * **Example:** * * ```php * // $content, instance of: Content\Model\Entity\Content * $this->render($content); * * // $block, instance of: Block\Model\Entity\Block * $this->render($block); * * // $field, instance of: Field\Model\Entity\Field * $this->render($field); * ``` * * When rendering objects the `Render.<ClassName>` event is automatically * triggered. For example, when rendering a Content Entity the following event * is triggered, and event handlers should provide a HTML representation of the * given object, it basically works as the `__toString()` magic method: * * ```php * $someContent = TableRegistry::get('Content.Contents')->get(1); * $this->render($someContent); * // triggers: Render.Content\Model\Entity\Content * ``` * * It is not limited to Entity instances only, you can virtually define a * `Render` for any class name. * * You can pass an unlimited number of arguments to your `Render` as follow: * * ```php * $this->render($someObject, $arg1, $arg2, ...., $argn); * ``` * * Your Render event-handler may look as below: * * ```php * public function renderMyObject(Event $event, $theObject, $arg1, $arg2, ..., $argn); * ``` */ public function render($view = null, $layout = null) { $html = ''; if (is_object($view)) { $className = get_class($view); $args = func_get_args(); array_shift($args); $args = array_merge([$view], (array) $args); // [entity, options] $event = new Event("Render.{$className}", $this, $args); EventManager::instance()->dispatch($event); $html = $event->result; } else { if (isset($this->jQuery)) { $this->jQuery->load(['block' => true]); } if (!$this->_hasRendered) { $this->_hasRendered = true; $this->_setTitle(); $this->_setDescription(); $html = parent::render($view, $layout); } } // parse shortcodes if not layout was applied if (!$layout || !$this->autoLayout()) { $this->shortcodes($html); } return $html; }
public function notifications($user = null, $page = 1) { // Getting the Activities personalized feed // NEW : User must subscribe individually to each Pole's Feed to be notified. // We only get the Activities for which the User is not the creator // that were created after the last time he read them. if (!$user) { $user = $this->loggedInUser->id; } // Then get all the subscriptions $Subscriptions = TableRegistry::get('Social.Subscriptions'); $subscriptions = $Subscriptions->find()->where(['Subscriptions.user_id' => $user])->all(); $subscriptions = (new Collection($subscriptions))->extract('feed_id')->toArray(); $query = $this->Activities->find()->contain(['Authors' => ['fields' => ['id', 'first_name', 'last_name', 'avatar']]])->limit(__MAX_NOTIFICATIONS_LISTED)->page($page)->order(['Activities.created DESC'])->matching('Feeds', function ($q) use($subscriptions) { return $q->where(['Feeds.id IN' => $subscriptions]); }); if ($this->request->is('ajax')) { if (isset($this->request->query['last_check'])) { $last_check = Time::createFromTimestamp($this->request->query['last_check'] / 1000); $activities = $query->where(['Activities.subject_id !=' => $user, 'Activities.created >' => $last_check->format('Y-m-d H:i:s')])->all(); } else { $activities = $query->where(['Activities.subject_id !=' => $user])->all(); } $count = $this->Activities->find()->contain(['Authors' => ['fields' => ['id', 'first_name', 'last_name', 'avatar']]])->limit(20000)->order(['Activities.created DESC'])->where(['Activities.subject_id !=' => $user, 'Activities.created >' => $this->loggedInUser->notifications_last_read])->matching('Feeds', function ($q) use($subscriptions) { return $q->where(['Feeds.id IN' => $subscriptions]); })->count(); $view = new View($this->request, $this->response, null); $view->layout = 'ajax'; // layout to use or false to disable $view->set('loggedInUser', $this->loggedInUser); $view->set('all_poles', $this->all_poles->toArray()); $view->set('activities', $activities->toArray()); $data['html'] = $view->render('Social.Activities/ajax_notifications'); $this->layout = 'ajax'; $data['count'] = $count; $data['success'] = true; $this->set('data', $data); $this->render('/Shared/json/data'); } else { $activities = $query->where(['Activities.subject_id !=' => $user])->all(); $this->set('activities', $activities->toArray()); // UI $this->set('section_title', __('Notifications')); $this->set('page_title', __('Notifications')); // Handling the breadcrumb $this->breadcrumb = array(__('Notifications') => '#'); } }
/** * Render view template or return serialized data. * * ### Special parameters * `_serialize` To convert a set of view variables into a serialized form. * Its value can be a string for single variable name or array for multiple * names. If true all view variables will be serialized. If unset normal * view template will be rendered. * * @param string|null $view The view being rendered. * @param string|null $layout The layout being rendered. * @return string|null The rendered view. */ public function render($view = null, $layout = null) { $serialize = false; if (isset($this->viewVars['_serialize'])) { $serialize = $this->viewVars['_serialize']; } if ($serialize !== false) { $result = $this->_serialize($serialize); if ($result === false) { throw new RuntimeException('Serialization of View data failed.'); } return (string) $result; } if ($view !== false && $this->_getViewFileName($view)) { return parent::render($view, false); } }
/** * Render the cell. * * @param string|null $template Custom template name to render. If not provided (null), the last * value will be used. This value is automatically set by `CellTrait::cell()`. * @return string The rendered cell * @throws \Cake\View\Exception\MissingCellViewException When a MissingTemplateException is raised during rendering. */ public function render($template = null) { if ($template !== null && strpos($template, '/') === false) { $template = Inflector::underscore($template); } if ($template === null) { $template = $this->template; } $this->View = null; $this->getView(); $this->View->layout = false; $cache = []; if ($this->_cache) { $cache = $this->_cacheConfig($template); } $render = function () use($template) { $className = explode('\\', get_class($this)); $className = array_pop($className); $name = substr($className, 0, strpos($className, 'Cell')); $this->View->subDir = 'Cell' . DS . $name; try { return $this->View->render($template); } catch (MissingTemplateException $e) { throw new MissingCellViewException(['file' => $template, 'name' => $name]); } }; if ($cache) { return $this->View->cache(function () use($render) { echo $render(); }, $cache); } return $render(); }
/** * Render a PDF view. * * @param string|null $view The view being rendered. * @param string|null $layout The layout being rendered. * * @return string|null The rendered view. */ public function render($view = null, $layout = null) { $data = parent::render($view, $layout); if (!empty($data)) { // output body $rendered = explode('<!-- NEW PAGE -->', $data); foreach ($rendered as $page) { $this->pdf->AddPage(); $this->pdf->writeHTML($page); } } $res = $this->pdf->Output($this->options['file_name'], $this->options['dest']); if (in_array($this->options['dest'], ['S', 'E'])) { return $res; } return $data; }
/** * Instantiates the correct view class, hands it its data, and uses it to render the view output. * * @param string $view View to use for rendering * @param string $layout Layout to use * @return \Cake\Network\Response A response object containing the rendered view. * @link http://book.cakephp.org/2.0/en/controllers.html#Controller::render */ public function render($view = null, $layout = null) { $event = new Event('Controller.beforeRender', $this); $event = $this->getEventManager()->dispatch($event); if ($event->result instanceof Response) { $this->autoRender = false; return $event->result; } if ($event->isStopped()) { $this->autoRender = false; return $this->response; } $this->View = $this->createView(); $this->autoRender = false; $this->response->body($this->View->render($view, $layout)); return $this->response; }
public function renderView($templateFile, $options = []) { $view = new View($this->request, $this->response, null); $view->layout = false; if ($options) { $view->viewVars = $options; } $html = $view->render($templateFile); return $html; }
public function render($view = null, $layout = null) { $this->pdf = new Dompdf($this->config); $this->pdf->setPaper($this->config['size'], $this->config['orientation']); $this->set(compact('pdf')); $this->pdf->loadHtml(parent::render($view, $layout)); $this->pdf->render(); if (is_array($this->config['paginate'])) { $this->paginate(); } switch ($this->config['render']) { case 'browser': case 'stream': return $this->pdf->output(); case 'upload': $output = $this->pdf->output(); if (!file_put_contents($this->config['upload_filename'], $output)) { return false; } return $output; default: return $this->pdf->stream($this->config['filename']); } }