Skip to content

Instantly share code, notes, and snippets.

@HorlogeSkynet
Created June 21, 2018 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HorlogeSkynet/c84a4ae4d8cc09fb5c7be2186a8586db to your computer and use it in GitHub Desktop.
Save HorlogeSkynet/c84a4ae4d8cc09fb5c7be2186a8586db to your computer and use it in GitHub Desktop.
How to generate a HTML rendered file as of CakePHP 3 ?
<?php
use Cake\Filesystem\File;
use Cake\View\View;
/* ... */
// Instanciates a new View class.
$view = new View();
// Pass your data to the View object.
$view->set('foo', $foo);
$view->set('bar', $bar);
// Creates a new file, writes down the rendered view and closes it afterwards.
$file = new File(WWW_ROOT . 'your/path/to/your/file.html', true);
$file->write($view->render(false, 'your_layout')); # `Templates/Layout/your_layout.ctp`
$file->close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment