Issue
I'm using CakePHP 3.6.7 and my problem is that when I use associated data in control form I got the unable to emit headers warning.
Here's my code:
AppController.php initialize function (If the user is logged in, i retrieve all his data from here)
public function initialize() {
parent::initialize();
// Retrieve user data for all views
if($this->request->getSession()->read('Auth.User')) {
$this->user = $this->Users->get($this->request->getSession()->read('Auth.User.id'), [
'contain' => ['UserPersonalData']
]);
$this->set('user', $this->user);
$this->set('_serialize', 'user');
}
}
UserPersonalDataController.php initialize function
public function initialize()
{
parent::initialize();
}
UserPersonalDataController.php edit function
public function edit()
{
if ($this->request->is(['patch', 'post', 'put'])) {
$userPersonalData = $this->Users->patchEntity($this->user, $this->request->getData());
if ($this->Users->save($userPersonalData)) {
$this->Flash->success(__('The user personal data has been saved.'));
return $this->redirect($this->user->username);
}
$this->Flash->error(__('The user personal data could not be saved. Please, try again.'));
}
}
edit.ctp, the following form will throw the unable to emit headers warning in debug mode
<div class="container" style="padding: 2rem">
<div class="users form large-9 medium-8 columns content">
<?= $this->Form->create($user, [
'class' => 'form-signin',
]); ?>
<fieldset>
<legend><?= __('Edit User') ?></legend>
<?php
echo $this->Form->control('user_personal_data.firstName', ['required' => true, 'class' => 'form-control', 'placeholder' => 'First Name', 'label' => false]);
echo $this->Form->control('user_personal_data.lastName', ['required' => true, 'class' => 'form-control', 'placeholder' => 'Last Name', 'label' => false]);
echo $this->Form->control('user_personal_data.phone', ['required' => true, 'class' => 'form-control', 'placeholder' => 'Phone', 'label' => false]);
?>
</fieldset>
<?= $this->Form->button(__('Submit'), ['class' => 'btn btn-lg btn-primary btn-block' ]) ?>
<?= $this->Form->end() ?>
</div>
edit.ctp, the following form will not throw any warnings
<div class="container" style="padding: 2rem">
<div class="users form large-9 medium-8 columns content">
<?= $this->Form->create($user, [
'class' => 'form-signin',
]); ?>
<fieldset>
<legend><?= __('Edit User') ?></legend>
<?php
echo $this->Form->control('email', ['required' => true, 'class' => 'form-control', 'placeholder' => 'First Name', 'label' => false]);
?>
</fieldset>
<?= $this->Form->button(__('Submit'), ['class' => 'btn btn-lg btn-primary btn-block' ]) ?>
<?= $this->Form->end() ?>
</div>
As I said, if I use associated data in control() form helper, it will throw that warning in debug mode. If I'm not in debug mode it will work just fine but I'm worried about it. Thanks for the help!
EDIT: Here's a screenshot of the warning:
Solution
The problem is that, as Greg Schmidt said, I had a non well formated numeric value. Solved!
Answered By - Kigris
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.