function index() {
// you can have view variables.
$data = 'A view variable';
// create a builder (hint: new ViewBuilder() constructor works too)
$builder = $this->viewBuilder();
// configure as needed
$builder->layout('default');
$builder->template('index');
$builder->helpers(['Html']);
// create a view instance
$view = $builder->build(compact('data'));
// render to a variable
$output = $view->render();
}
2条答案
按热度按时间fcg9iug31#
ViewBuilder
是在CakePHP 3.1中引入的,它处理视图的渲染。当我想渲染一个变量时,我总是去看看发送电子邮件是如何工作的。从控制器:
rm5edbpk2#
对于 AJAX 请求/响应,我使用以下代码:
而
print.ctp
在Template/ControllerName
之下