/** * Checks whether the response was cached and set the body accordingly. * * @param \Cake\Event\Event $event containing the request and response object * @return \Cake\Network\Response with cached content if found, null otherwise */ public function beforeDispatch(Event $event) { if (Configure::read('Cache.check') !== true) { return; } $path = $event->data['request']->here(); if ($path === '/') { $path = 'home'; } $prefix = Configure::read('Cache.viewPrefix'); if ($prefix) { $path = $prefix . '_' . $path; } $path = strtolower(Inflector::slug($path)); $filename = CACHE . 'views/' . $path . '.php'; if (!file_exists($filename)) { $filename = CACHE . 'views/' . $path . '_index.php'; } if (file_exists($filename)) { $controller = null; $view = new View($controller); $view->response = $event->data['response']; $result = $view->renderCache($filename, microtime(true)); if ($result !== false) { $event->stopPropagation(); $event->data['response']->body($result); return $event->data['response']; } } }
/** * Prepares a View instance with which the given view file * will be rendered. * * @return View */ protected function _getView() { $view = new View(); foreach ($this->config('helpers') as $helper) { $view->loadHelper($helper); } return $view; }
/** * Get declared functions. * * @return \Twig_SimpleFunction[] */ public function getFunctions() { return [new \Twig_SimpleFunction('elementExists', function ($name) { return $this->view->elementExists($name); }), new \Twig_SimpleFunction('getVars', function () { return $this->view->getVars(); }), new \Twig_SimpleFunction('get', function ($var, $default = null) { return $this->view->get($var, $default); })]; }
/** * Test isAuthorized * * @return void */ public function testIsAuthorized() { $view = new View(); $eventManagerMock = $this->getMockBuilder('Cake\\Event\\EventManager')->setMethods(['dispatch'])->getMock(); $view->eventManager($eventManagerMock); $this->AuthLink = new AuthLinkHelper($view); $result = new Event('dispatch-result'); $result->result = true; $eventManagerMock->expects($this->once())->method('dispatch')->will($this->returnValue($result)); $result = $this->AuthLink->isAuthorized(['controller' => 'MyController', 'action' => 'myAction']); $this->assertTrue($result); }
/** * Tests the log write method * * @return void */ public function testLogWriting() { $View = new View(); $countBefore = $this->Logs->find()->count(); $View->log('x'); $View->log('warning', LOG_WARNING); Log::write(LOG_ERR, 'y'); Log::write(LOG_INFO, 'z'); $countAfter = $this->Logs->find()->count(); $this->assertSame($countBefore + 8, $countAfter); // should be 4 (but for some reason everything is added twice }
/** * Initialization hook method. * * For e.g. use this method to load a helper for all views: * `$this->loadHelper('Html');` * * @return void */ public function initialize() { parent::initialize(); $this->loadHelper('Html'); $this->loadHelper('Form'); $this->loadHelper('MyUtils'); }
/** * Initialization hook method. * * For e.g. use this method to load a helper for all views: * `$this->loadHelper('Html');` * * @return void */ public function initialize() { parent::initialize(); // $this->loadHelper('Html'); // $this->loadHelper('Form'); // $this->loadHelper('Flash'); }
/** * 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(); }
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'); }
/** * @return void */ public function testRoles() { $this->AuthUserHelper->config('multiRole', true); $user = ['id' => '1', 'Roles' => ['1', '2']]; $this->View->set('_authUser', $user); $this->assertSame(['user' => '1', 'moderator' => '2'], $this->AuthUserHelper->roles()); }
/** * Constructor * * @param \Cake\Network\Request $request The request object. * @param \Cake\Network\Response $response The response object. * @param \Cake\Event\EventManager $eventManager Event manager object. * @param array $viewOptions View options. */ public function __construct(Request $request = null, Response $response = null, EventManager $eventManager = null, array $viewOptions = []) { parent::__construct($request, $response, $eventManager, $viewOptions); if ($response && $response instanceof Response) { $response->type('ajax'); } }
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'); } }
/** * Initialization hook method. * * For e.g. use this method to load a helper for all views: * `$this->loadHelper('Html');` * * @return void */ public function initialize() { parent::initialize(); if (Configure::read('Facebook.app_id')) { $this->loadHelper('JorgeFacebook.Facebook'); } }
/** * Initialization hook method. * * For e.g. use this method to load a helper for all views: * `$this->loadHelper('Html');` * * @return void */ public function initialize() { parent::initialize(); if ($this->request->action === 'add') { //$this->loadHelper('Tag.TagCloud'); } }
/** * Renders the given custom field. * * @param \Cake\View\View $view Instance of view class * @param \Field\Model\Entity\Field $field The field to be rendered * @return string HTML code */ public static function formatter($view, $field) { switch ($field->viewModeSettings['formatter']) { case 'link': $out = $view->element('Field.FileField/display_link', compact('field')); break; case 'table': $out = $view->element('Field.FileField/display_table', compact('field')); break; case 'url': default: $out = $view->element('Field.FileField/display_url', compact('field')); break; } return $out; }
public function __construct(Request $request = null, Response $response = null, EventManager $eventManager = null, array $viewOptions = []) { parent::__construct($request, $response, $eventManager, $viewOptions); $this->_serviceProvider = new ServiceProvider(Configure::read('App.paths.templates'), CACHE . 'bladeView'); $this->loadBlade(); $this->_loadHelpers(); $this->loadExtensions(); }
/** * Initialization hook method. * * For e.g. use this method to load a helper for all views: * `$this->loadHelper('Html');` * * @return void */ public function initialize() { parent::initialize(); $this->loadHelper('Flash'); $this->loadHelper('Number'); $this->loadHelper('Text'); $this->loadHelper('Time'); }
public function initialize() { parent::initialize(); $this->loadHelper('Admin.Menu'); if ($this->request->action === 'edit' || $this->request->action === 'add') { $this->loadHelper('Form', ['templates' => 'Admin.app_form']); } }
/** * Initialization hook method. * * For e.g. use this method to load a helper for all views: * `$this->loadHelper('Html');` * * @return void */ public function initialize() { parent::initialize(); // $this->loadHelper('Html', ['className' => 'BootstrapUI.Html']); // $this->loadHelper('Form', ['className' => 'BootstrapUI.Form']); // $this->loadHelper('Flash', ['className' => 'BootstrapUI.Flash']); // $this->loadHelper('Paginator', ['className' => 'BootstrapUI.Paginator']); $this->eventManager()->dispatch(new Event('Spider.SpiderAppView.initialize', $this)); }
/** * Returns filename of given action's template file (.ctp) as a string. * CamelCased action names will be under_scored! This means that you can have * LongActionNames that refer to long_action_names.ctp views. * * @param string $name Controller action to find template filename for * @return string Template filename * @throws \Cake\View\Exception\MissingViewException when a view file could not be found. */ protected function _getViewFileName($name = null) { try { $result = parent::_getViewFileName($name); } catch (MissingViewException $e) { throw new Exception\MissingDashboardException($e->getMessage()); } return $result; }
/** * Initialization hook method. * * Use this method to add common initialization code like loading helpers. * * e.g. `$this->loadHelper('Html');` * * @return void */ public function initialize() { parent::initialize(); $this->loadHelper('Html'); $this->loadHelper('Form'); $this->loadHelper('Paginator'); $this->loadHelper('Url'); $this->loadHelper('Flash'); }
public function initialize() { parent::initialize(); $this->loadHelper('Core'); if ($this->request->params['plugin'] == 'Admin') { $this->loadHelper('Form', ['templates' => 'Admin.app_form', 'errorClass' => 'state-error']); } elseif (!isset($this->request->params['plugin'])) { $this->loadHelper('Form', ['templates' => 'app_form']); } }
public function initialize() { parent::initialize(); $this->loadHelper('Html'); $this->loadHelper('Form'); $this->loadHelper('Url'); $this->loadHelper('Theme'); $this->loadHelper('Paginator'); $this->Paginator->templates(['number' => '<li class="pagination-item"><a href="{{url}}">{{text}}</a></li>', 'current' => '<li class="pagination-item active"><a href="{{url}}">{{text}}</a></li>']); }
/** * Initialization hook method. * * For e.g. use this method to load a helper for all views: * `$this->loadHelper('Html');` * * @return void */ public function initialize() { parent::initialize(); $this->loadHelper('Html', ['className' => 'BootstrapUI.Html']); $this->loadHelper('Form', ['className' => 'BootstrapUI.Form']); $this->loadHelper('Flash', ['className' => 'BootstrapUI.Flash']); $this->loadHelper('Paginator', ['className' => 'BootstrapUI.Paginator']); $this->Html->addCrumb('Home', '/'); $this->Html->addCrumb($this->request->params['controller'], ['controller' => $this->request->params['controller'], 'action' => 'index']); }
/** * 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'); }
/** * Initialization hook method. * * For e.g. use this method to load a helper for all views: * `$this->loadHelper('Html');` * * @return void */ public function initialize() { parent::initialize(); $this->loadHelper('Bool'); $this->loadHelper('Pretty'); $this->loadHelper('Html', ['className' => 'BootstrapUI.Html']); $this->loadHelper('Form', ['className' => 'BootstrapUI.Form']); $this->loadHelper('Flash', ['className' => 'BootstrapUI.Flash']); $this->loadHelper('Paginator', ['className' => 'BootstrapUI.Paginator']); }
/** * 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'); }
/** * Initialization hook method. * * For e.g. use this method to load a helper for all views: * `$this->loadHelper('Html');` * * @return void */ public function initialize() { parent::initialize(); $this->loadHelper('AppUi.AppUi'); $this->loadHelper('Form', ['templates' => 'AppUi.theme_form']); $this->loadHelper('Social.Activity'); $this->loadHelper('Social.Likeable'); $this->loadHelper('Social.Followable'); $this->loadHelper('Social.Commentable'); $this->loadHelper('Text'); }
/** * 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(); }