I'm facing a very wierd situation concerning a quite simple task. I'm trying to create a very simple edit form in my application using cakephp 3.x version.
In my ContentsController::edit($contentID) method I'm loading the content entity to be edited like this
$content = $this->Contents->findById($contentID)->first()
and then I'm simply creating the respective view variable using set() method like that:
$this->set('content', $content);
In the view file - named edit.ctp - all I'm doing is to simply create
a new form using FormHelper using the following piece of code:
<h2><?= __('Edit content: ') . $content->title; ?></h2>
<?php
echo $this->Form->create($content);
echo $this->Form->input('title', ['type' => 'text']);
echo $this->Form->input('alias', ['type' => 'text']);
echo $this->Form->input('body', ['type' => 'textarea']);
echo $this->Form->submit();
?>
The following code creates the form correctly but it does not load the default values in each input element from the $content entity. After doing some digging into the source code of the FormHelper I found out that when the FormHelper::create() method is called, it correctly loads the EntityContext interface using the $content entity. But for some reason, which I cannot explain, in each of the FormHelper::input() calls, internally the context interface is switching to NullContext so no data is loaded into the field.
Does anyone have an idea what am I doing wrong with that piece of code?
$this->Contents->findById($contentID)->first()for$this->Contents->get($contentID)here you have more info - Jacek B Budzynski