我正在使用CakePHP 3.6.7,我的问题是当我以控件形式使用关联数据时,出现无法发出标题警告的情况。
这是我的代码:
AppController.php初始化函数(如果用户已登录,我将从此处检索其所有数据)
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初始化函数
public function initialize()
{
parent::initialize();
}
UserPersonalDataController.php编辑功能
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,以下格式将在调试模式下引发无法发出标头的警告
<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,以下格式不会引发任何警告
<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>
正如我所说,如果我在control()窗体帮助器中使用关联的数据,它将在调试模式下抛出该警告。如果我不处于调试模式,它将可以正常工作,但我对此感到担心。 感谢您的帮助!
答案 0 :(得分:0)
问题是,正如Greg Schmidt所说,我有一个格式不正确的数值。解决了!