我有一个cakephp应用程序,其中Payments表有许多应用程序,
我正在尝试使用下面的代码保存,但是没有保存付款数据,只保存了应用程序数据。
public function add()
{
$application = $this->Applications->newEntity();
if ($this->request->is('post')) {
$application = $this->Applications->patchEntity($application, $this->request->getData(),
[ 'associated'=>['Payments'] ]);
//debug($application);
//exit;
if ($this->Applications->save($application)) {
$this->Flash->success(__('The application has been saved.'));
//debug($application);
//exit();
return $this->redirect(['action' => 'view', $application['id']]);
}
$this->Flash->error(__('The application could not be saved. Please, try again.'));
}
$tasks = $this->Applications->Tasks->find('list', ['limit' => 200]);
$this->set(compact('application', 'tasks'));
}
请问可能出错?
\ src \ Controller \ ApplicationsController.php(第58行)
[
'tasks_id' => '5',
'refnumber' => '1519062454350860',
'payment' => [
(int) 0 => [
'refnumber' => '1519062454350860'
]
],
'surname' => 'asdf',
'othernames' => 'Opeoluwa Clement',
'gender' => 'male',
'phone' => '08060595019',
'email' => 'clementcrownrise@gmail.com',
'canid' => 'asdfasd',
'examinationpassed' => 'Post Fellowship Certificate',
'monthofexaminationpassed' => 'April',
'yearofexaminationpassed' => '1950',
'transcriptaddress' => 'Lagos State University',
'status' => 'Opened',
'applicationletter' => [
'tmp_name' => 'C:\wamp\tmp\php69B1.tmp',
'error' => (int) 0,
'name' => 'OAGCOurse.jpg',
'type' => 'image/jpeg',
'size' => (int) 189739
],
'postinglog' => [
'tmp_name' => 'C:\wamp\tmp\php69E1.tmp',
'error' => (int) 0,
'name' => 'OAGCOurse.jpg',
'type' => 'image/jpeg',
'size' => (int) 189739
],
'certificate' => [
'tmp_name' => 'C:\wamp\tmp\php6A11.tmp',
'error' => (int) 0,
'name' => 'OAGCOurse.jpg',
'type' => 'image/jpeg',
'size' => (int) 189739
],
'evidenceofpayment' => [
'tmp_name' => 'C:\wamp\tmp\php6A41.tmp',
'error' => (int) 0,
'name' => 'OAGCOurse.jpg',
'type' => 'image/jpeg',
'size' => (int) 189739
],
'annualdues' => [
'tmp_name' => 'C:\wamp\tmp\php6A70.tmp',
'error' => (int) 0,
'name' => 'OAGCOurse.jpg',
'type' => 'image/jpeg',
'size' => (int) 189739
]
]
警告(2):mb_strlen()期望参数1为字符串,给定数组 [CORE \ src \ Validation \ Validation.php,第742行]
\ src \ Controller \ ApplicationsController.php(第59行)
object(App\Model\Entity\Application) {
'tasks_id' => (int) 3,
'surname' => 'clement',
'othernames' => 'Opeoluwa Clement',
'gender' => 'female',
'phone' => '08060595019',
'email' => 'clementcrownrise@gmail.com',
'canid' => 'asdfasd',
'examinationpassed' => 'Part 1/Membership',
'transcriptaddress' => 'Lagos State University',
'status' => 'Opened',
'applicationletter' => [
'tmp_name' => 'C:\wamp\tmp\php7E70.tmp',
'error' => (int) 0,
'name' => 'fav.png',
'type' => 'image/png',
'size' => (int) 13893
],
'postinglog' => [
'tmp_name' => 'C:\wamp\tmp\php7E90.tmp',
'error' => (int) 0,
'name' => 'fav.png',
'type' => 'image/png',
'size' => (int) 13893
],
'certificate' => [
'tmp_name' => 'C:\wamp\tmp\php7ED0.tmp',
'error' => (int) 0,
'name' => 'fav.png',
'type' => 'image/png',
'size' => (int) 13893
],
'evidenceofpayment' => [
'tmp_name' => 'C:\wamp\tmp\php7EFF.tmp',
'error' => (int) 0,
'name' => 'OAGCOurse.jpg',
'type' => 'image/jpeg',
'size' => (int) 189739
],
'annualdues' => [
'tmp_name' => 'C:\wamp\tmp\php7F4F.tmp',
'error' => (int) 0,
'name' => 'OAGCOurse.jpg',
'type' => 'image/jpeg',
'size' => (int) 189739
],
'[new]' => true,
'[accessible]' => [
'surname' => true,
'othernames' => true,
'gender' => true,
'email' => true,
'phone' => true,
'examinationpassed' => true,
'canid' => true,
'transcriptaddress' => true,
'applicationletter' => true,
'postinglog' => true,
'certificate' => true,
'evidenceofpayment' => true,
'annualdues' => true,
'tasks_id' => true,
'status' => true,
'modified' => true,
'created' => true,
'task' => true
],
'[dirty]' => [
'tasks_id' => true,
'surname' => true,
'othernames' => true,
'gender' => true,
'phone' => true,
'email' => true,
'canid' => true,
'examinationpassed' => true,
'transcriptaddress' => true,
'status' => true,
'applicationletter' => true,
'postinglog' => true,
'certificate' => true,
'evidenceofpayment' => true,
'annualdues' => true
],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Applications'
}
答案 0 :(得分:0)
根据您的关联,您已在应用程序模型中进行了操作。别名为' 付款 '不是' 付款 ',因此更改' 付款'到' 付款'在您的表单输入字段中。像
echo $this->Form->input('payments.0.refnumber', ['value' => '1519062454350860']);
所以getData();将像
一样返回数组'tasks_id' => '5',
'refnumber' => '1519062454350860',
'payments' => [ //note it's not payment
(int) 0 => [
'refnumber' => '1519062454350860'
]
],
这将解决您的问题
编辑: -
$application = $this->Applications->patchEntity($application, $this->request->getData(),
[
'validation' => false,
'associated'=> [
'Payments' => ['validation' => false]
]
]);