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' 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.
Is there a way to connect my new ViewBuilder
to the main Cake\Http\ServerRequest
of the application?
$this->getRequest()
as a second argument toviewBuilder::build()
. You're right that this needs refactoring, but will have to make it work in its current state anyway. Do you mind posting this as an answer? That way I can accept it and close the question. – Stripe