Created
June 21, 2018 09:17
-
-
Save HorlogeSkynet/c84a4ae4d8cc09fb5c7be2186a8586db to your computer and use it in GitHub Desktop.
How to generate a HTML rendered file as of CakePHP 3 ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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