1

我已经安装了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.');
            }
        }
    }
4

2 回答 2

0

该插件仅适用于一种型号。您可以将更多上传器添加到您的网站。该模型似乎很好,我建议您查看您的表单,看看您是否以正确的方式将表单创建到您的视图中(放入您的表单很重要:'type' => 'file' 例如:

echo $this->Form->create('Product', array ('class' => 'form', 'type' => 'file')); 
echo $this->Form->input('ModelImage.filename', array('type' => 'file'));
echo $this->Form->submit('Add Image', array('id'=>'add_image'));
echo $this->Form->end();

或者问题是名称Use尝试用另一个名称更改名称

于 2012-10-21T14:34:34.577 回答
0

在与 Alessandro 一起检查代码后 [谢谢 :)] 我发现了问题。

如果您查看视图和控制器代码,您可以看到模型名为“使用”。这就是问题所在,因为 Use 是 PHP 中的一个加载词,我不应该将它用作模型名称。

我将模型重命名为 Outcome,现在 Uploader 可以完美运行。

于 2012-10-22T11:25:50.070 回答