gpt4 book ai didi

php - saveMany 验证无法正常工作

转载 作者:可可西里 更新时间:2023-10-31 23:29:53 26 4
gpt4 key购买 nike

我正在尝试使用最新的 2.x CakePHP 版本来执行此操作,我正在尝试通过验证来上传多个文件表单,但无法正常工作...

DocsController.php( Action 添加)

if ($this->request->is('post')) {
if ($this->Doc->saveMany($this->request->data, array('deep' => true))) {
$this->Session->setFlash(__('Ok'));
} else {
debug($this->Doc->validationErrors); die();
$this->Session->setFlash(__('Error'));
}
$this->redirect($this->referer());
}

添加.ctp

<?php
echo $this->Form->create('Doc', array('type' => 'file'));
echo $this->Form->input('files.', array(
'label' => __("New document",true), 'type' => 'file',
'div' => 'input text no',
'multiple' => 'multiple',
'required' => true,
));
echo $this->Form->end('Upload');
?>

Doc.php

class Doc extends AppModel {

public $belongsTo = array(
'Project' => array(
'className' => 'Project',
'foreignKey' => 'project_id',
)
);

public $validate = array(
'files' => array(
'rule' => array('extension', array('pdf')),
'required' => false,
'allowEmpty' => true,
'message' => 'Only pdf files'
),
);
}

数组

这个错误是正常的:

Array
(
[Doc] => Array
(
[files] => Array
(
[0] => Array
(
[name] => images.jpeg
[type] => image/jpeg
[tmp_name] => /private/var/tmp/phpSqerRI
[error] => 0
[size] => 5740
)

)

)

)

/app/Controller/DocsController.php (line 112)
array(
'Doc' => array(
'files' => array(
(int) 0 => 'Only pdf files'
)
)
)

这就是问题所在:

Array
(
[Doc] => Array
(
[files] => Array
(
[0] => Array
(
[name] => 4_54718093804437603.pdf
[type] => application/pdf
[tmp_name] => /private/var/tmp/phpCfUUDx
[error] => 0
[size] => 1441232
)

)

)

)

/app/Controller/DocsController.php (line 112)
array(
'Doc' => array()
)

它是 PDF,所以没问题,但验证返回数组

如果没有违反规则,为什么要返回数组?

编辑 1

错误来自 saveMany,因为检查验证说“好的”...但没有更多信息 atm.....

$this->Doc->set($this->request->data);
if ($this->Doc->validates()) {
// success
die("Ok");
} else {
// failed
$errors = $this->Doc->validationErrors;
die(print_r($errors));
}

提前致谢,对不起我的英语。

最佳答案

cake2中saveMany的保存格式有问题:)

数组应该像 0 => Doc => array ('fieldname')

关于php - saveMany 验证无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31193626/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com