本文整理汇总了PHP中Cake\View\View::render方法的典型用法代码示例。如果您正苦于以下问题:PHP View::render方法的具体用法?PHP View::render怎么用?PHP View::render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\View\View
的用法示例。
在下文中一共展示了View::render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* 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;
}
示例2: render
/**
* 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');
}
示例3: render
/**
* 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();
}
示例4: _testEnabled
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();
}
示例5: render
/**
* 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);
}
示例6: render
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');
}
}
示例7: render
/**
* 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();
}
示例8: 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');
}
示例9: render
/**
* 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();
}
示例10: 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');
}
示例11: render
/**
* 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);
}
}
示例12: render
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);
}
示例13: render
/**
* 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);
}
示例14: render
/**
* 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);
}
示例15: get_for_parent
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');
}