Когда я запускаю это, я вижу следующее в $ this-> request-> data:
Array
(
[Information] => Array
(
[name] => Test
[lastname] => Name
[email] => test@example.com
[mobile_phone] => 1561561566
[home_phone] => 1521521522
[address] => 123 Any Street
[other_information] => Other information
[picture] => Array
(
[name] => avatar.png
[type] => image/png
[tmp_name] => /tmp/php2Jvveh
[error] => 0
[size] => 89486
)
)
[Education] => Array
(
[0] => Array
(
[education_content] =>
)
)
[Experience] => Array
(
[0] => Array
(
[experience_content] =>
)
)
)
Вы заметите, что массив Education и Experience, хотя и пустой, все еще существуют в$this->request->data
.Поскольку вы используете $this->Information->saveAll($this->request->data)
, он сохранит пустой набор данных в таблицу.Если вы не хотите сохранять пустые данные, проверьте массив, чтобы убедиться, что он пуст.Если это так, отключите его, прежде чем сохранить все.То, как вы настроили форму, было бы примерно так:
if (empty($this->request->data['Experience'][0]['experience_content'])) {
unset($this->request->data['Experience']);
}
if (empty($this->request->data['Education'][0]['education_content'])) {
unset($this->request->data['Education']);
}
$this->Information->create();
if ($this->Information->saveAll($this->request->data)) {
...snip...