我已经安装了Miles Johnson 的 Uploader 插件,并使用我的一个模型对其进行了设置,并使其完美运行。非常好。
然后我用几乎相同的代码在另一个模型上设置它[唯一的区别是上传路径],它不适用于第二个模型。当我提交表单时,插件似乎没有注意到;尝试将 POST 文件数组直接插入数据库时出现 SQL 错误。
这是代码。[除此之外,插件在引导程序中导入]
public $actsAs = array(
'Uploader.Attachment' => array(
'photo' => array(
'name' => 'formatFileName',
'uploadDir' => '/uploads/uses/img/',
'dbColumn' => 'photo',
'maxNameLength' => 30,
'overwrite' => true,
'stopSave' => true,
'allowEmpty' => false,
'transforms' => array(
array('method' => 'resize', 'width' => 240, 'dbColumn' => 'photo_thumb'))
)
),
'Uploader.FileValidation' => array(
'fileName' => array(
'extension' => array('gif', 'jpg', 'png', 'jpeg'),
'required' => true
)
)
);
这是在未上传的模型上,唯一的区别是uploadDir。
该插件是否仅适用于一种型号?有什么线索吗?谢谢:}
编辑以获得额外的清晰度
这是我的视图代码:
echo $this->Form->create('Use', array('type' => 'file'));
echo $this->Form->input('Use.photo', array('type' => 'file'));
echo $this->Form->input('Use.desc', array('rows' => '3', 'label' => 'Description'));
echo $this->Form->end('Add to Gallery');
这是我的控制器代码:
public function add() {
if ($this->request->is('post')) {
$this->Use->set('user_id', $this->Auth->user('id'));
if ($this->Use->save($this->request->data)) {
$this->Session->setFlash('Your Use has been saved.');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Unable to add your Use.');
}
}
}