将`new \ Cake \ View \ ViewBuilder()`连接到主`\ Cake \ Http \ ServerRequest` [英] Connecting `new \Cake\View\ViewBuilder()` to the main `\Cake\Http\ServerRequest`
问题描述
我正在通过新的独立的 ViewBuilder
将视图模板渲染为变量.
I'm rendering a view template into a variable via a new, standalone ViewBuilder
.
$builder = new \Cake\View\ViewBuilder();
$builder->setLayout('my_layout');
$builder->setTemplate('my_template');
上面的模板包含一个表格.
The above template contains a form.
echo $this->Form->create(null, array(
'type' => 'POST',
'url' => '/',
)).PHP_EOL;
$this->Form->unlockField('my_input');
echo $this->Form->end();
提交后,将导致以下错误.
When submitted, it results in the below error.
在请求数据中找不到"_ Token".
'_Token' was not found in request data.
As far as I understand, the tokens aren't being added because the FormHelper
receives false
when it checks for $this->_View->getRequest()->getParam('_Token')
, and that is because this new ViewBuilder
isn't connected to the actual request the application operates on.
是否可以将新的 ViewBuilder
连接到应用程序的主 Cake \ Http \ ServerRequest
?
Is there a way to connect my new ViewBuilder
to the main Cake\Http\ServerRequest
of the application?
推荐答案
You can pass it to $builder->build, it's the the 2nd argument, you can normally get it from $this->getRequest().
这篇关于将`new \ Cake \ View \ ViewBuilder()`连接到主`\ Cake \ Http \ ServerRequest`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!