将`new \ Cake \ View \ ViewBuilder()`连接到主`\ Cake \ Http \ ServerRequest` [英] Connecting `new \Cake\View\ViewBuilder()` to the main `\Cake\Http\ServerRequest`

查看:96
本文介绍了将`new \ Cake \ View \ ViewBuilder()`连接到主`\ 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.

据我了解,由于 FormHelper 接收到 false

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆