使用Miles J Uploader插件时出现Cakephp错误

使用Miles J Uploader插件时出现Cakephp错误,cakephp,plugins,model,controller,Cakephp,Plugins,Model,Controller,我目前正在尝试使用位于此处的Miles J插件,尽管我在学习CakePhp方面取得了很大的进步,但我目前在使用该插件时遇到了问题,我非常感谢提供的任何帮助 我已经按照所有必要的步骤使用插件。它已经被下载放在插件文件夹中,我用CakePlugin::loadAll引导 到目前为止还不错 接下来,我将按照插件开发人员的指示设置表 好,现在回到我自己的代码。我有以下设置: image\u controller.php、image.php及其视图 我现在的目标是在这些文件中使用插件: App::impo

我目前正在尝试使用位于此处的Miles J插件,尽管我在学习CakePhp方面取得了很大的进步,但我目前在使用该插件时遇到了问题,我非常感谢提供的任何帮助

我已经按照所有必要的步骤使用插件。它已经被下载放在插件文件夹中,我用CakePlugin::loadAll引导

到目前为止还不错

接下来,我将按照插件开发人员的指示设置表

好,现在回到我自己的代码。我有以下设置:

image\u controller.php、image.php及其视图

我现在的目标是在这些文件中使用插件:

App::import('Vendor', 'Uploader.Uploader');

Class ImagesController extends AppController {

     var $components = array('Auth');
     var $helpers = array('Design');
     var $uses = array('Image', 'Uploader.Upload');

     function manage(){
         //here I show a simple upload form that uses the action saveimage 
     }

     function saveimage(){

          $this->Uploader = new Uploader();
          if(!empty($this->data)){
               $this->Upload->save($this->data);
          }


     }



}
现在,我的模型设置如下

Class Image extends AppModel {

       public $useTable = 'uploads';
       public $actsAs = array(
        'Uploader.FileValidation' => array(
            'file' => array(
                'extension' => array(
                    'value' => array('gif', 'jpg', 'jpeg'),
                    'error' => 'Only gif, jpg and jpeg images are allowed!'
                ),
                'minWidth' => 500,
                'minHeight' => 500,
                'required' => true
            ),
            'import' => array(
                'required' => false
            )
        ),
        'Uploader.Attachment' => array(
            'file' => array(
                'name' => 'uploaderFilename',
                'uploadDir' => '/files/uploads/',
                'dbColumn' => 'path',
                'maxNameLength' => 30,
                'overwrite' => true,
                'stopSave' => false,
                'transforms' => array(
                    // Save additional images in the databases after transforming
                    array(
                        'method' => 'resize',
                        'width' => 100,
                        'height' => 100,
                        'dbColumn' => 'path_alt'
                    )
                ),
                'metaColumns' => array(
                    'size' => 'filesize',   // The size value will be saved to the filesize column
                    'type' => 'type'        // And the same for the mimetype
                )
            ),
            'import' => array(
                'uploadDir' => '/files/uploads/',
                'name' => 'uploaderFilename',
                'dbColumn' => 'path',
                'overwrite' => true,
                'stopSave' => false,
                'transforms' => array(
                    array(
                        'method' => 'scale',
                        'percent' => .5,
                        'dbColumn' => 'path' // Overwrite the original image
                    )
                )
            )
        )
    );


}

}
出于测试目的,在我的模型上,我没有做任何更改,只是复制并粘贴了与插件内的Test/model文件夹中所示相同的数组,用于显示插件的功能

出现以下混乱、错误或缺乏理解:

我的文件未上载到webroot/files/uploads文件夹 正在将我的数据插入数据库,但未完全插入,请保留为空,如图所示:

id | caption | path | path_alt | created  |
4  |         |      |          |2012:02:..|
在上面,我希望路径被保存,但它没有

我必须承认我的困惑主要是因为我没有使用插件的经验,所以我意识到我可能在模型或配置方面做了一些错误的事情

如果能得到及时的帮助,我将不胜感激,因为我曾试图自己解决这个问题,但没有取得任何成功

有几件事:

1-在控制器中,不需要导入Uploader类。您也不需要使用Uploader.Upload模型,它只是一个示例测试用例。在控制器中需要做的就是调用$this->Image->save,如果您在Image中定义了附件,它将上传文件并将路径作为一行保存到数据库中

2-在视图中,创建文件输入。注意输入的名称

echo $this->Form->input('FILE_INPUT_NAME', array('type' => 'file'));
3-在图像模型中,为特定输入字段设置AttachmentBehavior及其选项:

'Uploader.Attachment' => array(
    'FILE_INPUT_NAME' => array(
        'uploadDir' => '/files/uploads/',
        'dbColumn' => 'path'
    ),
    'ANOTHER_INPUT' => array()
);
确保列路径存在于图像表中。就这样

有关每个选项的作用的更多信息,请查看以下内容:

一些事项:

1-在控制器中,不需要导入Uploader类。您也不需要使用Uploader.Upload模型,它只是一个示例测试用例。在控制器中需要做的就是调用$this->Image->save,如果您在Image中定义了附件,它将上传文件并将路径作为一行保存到数据库中

2-在视图中,创建文件输入。注意输入的名称

echo $this->Form->input('FILE_INPUT_NAME', array('type' => 'file'));
3-在图像模型中,为特定输入字段设置AttachmentBehavior及其选项:

'Uploader.Attachment' => array(
    'FILE_INPUT_NAME' => array(
        'uploadDir' => '/files/uploads/',
        'dbColumn' => 'path'
    ),
    'ANOTHER_INPUT' => array()
);
确保列路径存在于图像表中。就这样


有关每个选项的作用的详细信息,请查看以下内容:

尝试使用model保存时,我也会收到以下消息:错误:SQLSTATE[42S22]:未找到列:1054“字段列表”中的未知列“数组”SQL查询:插入上载路径,创建值数组,“2012-03-01 03:38:14”注意:如果要自定义此错误消息,请创建app\View\Errors\pdo_error.ctp尝试使用模型保存时,我也会收到以下消息:错误:SQLSTATE[42S22]:未找到列:1054“字段列表”中的未知列“数组”SQL查询:插入上载路径,创建值数组,“2012-03-01 03:38:14”注意:如果您想自定义此错误消息,请创建app\View\Errors\pdo_error.ctphey我已按您所说的那样设置了所有内容。。。正在向数据库添加新行,但在目标目录中找不到图像。。。请帮忙……嘿,我已经按照你说的那样安排好了一切。。。正在向数据库添加新行,但在目标目录中找不到图像。。。请帮忙。。