Форма Cakephp не становится подчиненной, но выдает Уведомление (8): Массив в строку Coversion, многие другие Предупреждения (2)

У меня проблемы с отправкой / сохранением данных в CakePHP Model. Я построил форму как обычно, как обычно, но на этот раз я получаю уведомления и предупреждения, а также данные не сохраняются. Вот форма, которую я построил и метод в Controller:

educationaldetails.ctp

<?php
if (empty($Education)):

echo $this->Form->create('Candidate', array('class' => 'dynamic_field_form'));

echo $this->Form->input('CandidatesEducation.0.candidate_id', array(
'type' => 'hidden',
'value' => $userId
));

echo $this->Form->input('CandidatesEducation.0.grade_level', array(
'options' => array(
'Basic' => 'Basic',
'Masters' => 'Masters',
'Doctorate' => 'Doctorate',
'Certificate' => 'Certificate'
)
));

echo $this->Form->input('CandidatesEducation.0.course');

echo $this->Form->input('CandidatesEducation.0.specialization');

echo $this->Form->input('CandidatesEducation.0.university');

echo $this->Form->input('CandidatesEducation.0.year_started', array(
'type' => 'year'
));

echo $this->Form->input('CandidatesEducation.0.year_completed', array(
'type' => 'year'
));

echo $this->Form->input('CandidatesEducation.0.type', array(
'options' => array(
'Full' => 'Full',
'Part-Time' => 'Part-Time',
'Correspondence' => 'Correspondence'
)));

echo $this->Form->input('CandidatesEducation.0.created_on', array(
'type' => 'hidden',
'value' => date('Y-m-d H:i:s')
));

echo $this->Form->input('CandidatesEducation.0.created_ip', array(
'type' => 'hidden',
'value' => $clientIp
));

echo $this->Form->button('Submit', array('type' => 'submit', 'class' => 'submit_button'));

echo $this->Form->end();

endif;

CandidatesController.php

public function educationaldetails() {
$this->layout = 'front_common';

$this->loadModel('CandidatesEducation');

$Education = $this->CandidatesEducation->find('first', array(
'conditions' => array(
'candidate_id = ' => $this->Auth->user('id')
)
));

$this->set('Education', $Education);

// Checking if in case the Candidates Education is available then polpulate the form
if (!empty($Education)):
// If Form is empty then populating the form with respective data.
if (empty($this->request->data)):
$this->request->data = $Education;
endif;
endif;

if ($this->request->is(array('post', 'put')) && !empty($this->request->data)):

$this->Candidate->id = $this->Auth->user('id');
if ($this->Candidate->saveAssociated($this->request->data)):
$this->Session->setFlash('You educational details has been successfully updated', array(
'class' => 'success'
));
return $this->redirect(array(
'controller' => 'candidates',
'action' => 'jbseeker_myprofile',
$this->Auth->user('id')
));
else:
$this->Session->setFlash('You personal details has not been '
. 'updated successfully, please try again later!!', array(
'class' => 'failure'
));
endif;

endif;
}

Вот скриншот введите описание изображения здесь ошибок, которые я получаю, не могу понять, что происходит, когда другие формы работают правильно. выглядит что-то не так с видом?

1

Решение

Эта ошибка появляется, потому что вы не передаете правильные аргументы session->setFlash() метод, вы делаете так:

   $this->Session->setFlash('You personal details has not been updated successfully, please try again later!!', array(
'class' => 'failure'
));

В документы упоминается как:

   $this->Session->setFlash('You personal details has not been updated successfully, please try again later!!',
'default', array(
'class' => 'failure'
));
1

Другие решения

Привет, так что, если я понимаю:

array(
'CandidatesEducation' => array(
(int) 0 => array(
'candidate_id' => '5',
'grade_level' => 'Basic',
'course' => 'Masters of Computer Application',
'specialization' => '',
'university' => 'Mumbai University',
'year_started' => array(
'year' => '2011'
),
'year_completed' => array(
'year' => '2014'
),
'type' => 'Full',
'created_on' => '2014-11-27 15:44:36',
'created_ip' => '127.0.0.1'
)
)
),

Это ваши данные, и вам просто нужно сохранить это в вашей таблице candid_educations, так что в этом случае я бы сделал:

$this->Candidate->CandidatesEducation->save($this->request->data);

и ваши данные должны были выглядеть так:

array(
'CandidatesEducation' => array(
'candidate_id' => '5',
'grade_level' => 'Basic',
'course' => 'Masters of Computer Application',
'specialization' => '',
'university' => 'Mumbai University',
'year_started' => array(
'year' => '2011'
),
'year_completed' => array(
'year' => '2014'
),
'type' => 'Full',
'created_on' => '2014-11-27 15:44:36',
'created_ip' => '127.0.0.1'
)
);

saveAssociated используется при создании вашей модели А ТАКЖЕ Связанная модель, не только ваша ассоциированная модель.

И еще: я не уверен, что год_старт и год завершены, данные зависят от схемы вашей таблицы; какой тип year_completed и year_started?

0