【发布时间】:2012-03-01 08:06:36
【问题描述】:
我目前正在尝试使用位于 http://milesj.me/code/cakephp/uploader 的 Miles J 插件虽然我在学习 CakePhp 方面取得了很大进步,但我目前在使用该插件时遇到了问题,如果提供任何帮助,我将不胜感激。
我已按照使用插件的所有必要步骤进行操作。它已经下载到 Plugin 文件夹中,我使用 CakePlugin::loadAll() 引导。
到目前为止一切顺利。
接下来我按照插件开发者的指示设置表格。
好的,现在回到我自己的代码。我有以下设置:
images_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:..|
上面,我希望保存路径,但没有。
我不得不承认我的困惑主要来自于我没有使用插件的经验,所以我知道我可能在我的模型或配置方面做错了。
非常感谢任何及时的帮助,因为我试图自己解决这个问题,但没有成功。
【问题讨论】:
-
当尝试使用模型保存时,我也收到此消息:错误:SQLSTATE[42S22]:未找到列:1054 '字段列表'中的未知列'数组' SQL 查询:INSERT INTO
uploads(path,created) VALUES (Array, '2012-03-01 03:38:14') 注意:如果要自定义此错误信息,请创建 app\View\Errors\pdo_error.ctp
标签: cakephp plugins model controller