我在 cakephp 2 中有一个站点,我想使用 Miles J 的插件 Uploader 上传一个文件。但是返回这个错误:找不到列:1054 Unknown column 'Array' in 'field list'
SQL查询:
UPDATE `db148147_trimalcione`.`ingredient_images`
SET
`id` = 6,
`filename` = Array,
`ingredient_id` = 8,
`modified` = '2012-08-21 23:01:13'
WHERE `db148147_trimalcione`.`ingredient_images`.`id` = '6'
为什么?我创建了一个表成分图像,其中有列文件名。这是我的模型:
<?php
class IngredientImage extends AppModel {
public $name = 'IngredientImage';
public $useTable = 'ingredient_images';
public $actsAs = array (
'Uploader.Attachment' => array (
'filename' => array(
'name' => 'setNameAsImgId', // Name of the function to use to format filenames
'saveAsFilename' => true,
// 'baseDir' => '', // See UploaderComponent::$baseDir
'uploadDir' => '/files/ingredient_images/', // See UploaderComponent::$uploadDir
'dbColumn' => 'filename', // The database column name to save the path to
'defaultPath' => 'default.png', // Default file path if no upload present
'maxNameLength' => 20, // Max file name length
'overwrite' => true, // Overwrite file with same name if it exists - Se si effettua un transform è da usare al suo interno altrimenti c'è un override a false
'stopSave' => true, // Stop the model save() if upload fails
'allowEmpty' => true, // Allow an empty file upload to continue
'transforms' => array (
array('method' => 'resize', 'width' => 160, 'height' => 160, 'dbColumn' => 'filename', 'append' => false, 'overwrite' => true)
)
)
),
'Uploader.FileValidation' => array (
'filename' => array (
'maxWidth' => array (
'value' => 1280,
'error' => 'La lunghezza dell\'avatar non deve superare i 1280 pixel'
),
'maxHeight' => array (
'value' => 1280,
'error' => 'L\'altezza dell\'avatar non deve superare i 1280 pixel'
),
'extension' => array (
'value' => array('gif', 'jpg', 'png', 'jpeg'),
'error' => 'Il formato dell\'avatar deve essere una GIF, JPG o PNG'
),
'filesize' => array (
'value' => 5242880,
'error' => 'La dimensione dell\'avatar non deve superare i 500kB'
)
)
)
);
public $belongsTo = array(
'Ingredient' => array(
'className' => 'Ingredient',
'foreignKey' => 'ingredient_id',
'conditions' => '',
'order' => ''
)
);
public function setNameAsImgId ($name, $field, $file) {
/**
* Format the filename a specific way before uploading and attaching.
*
* @access public
* @param string $name - The current filename without extension
* @param string $field - The form field name
* @param array $file - The $_FILES data
* @return string
*/
// devo ricavare l'id dell'immagine appena creata per rinominare il file
return $this->id;
}
}
?>
这是我的控制器:
CakePlugin::load('Uploader');
App::import('Vendor', 'Uploader.Uploader');
//.. my action
$this->request->data['IngredientImage']['ingredient_id'] = $this->Ingredient->id;
$this->Ingredient->IngredientImage->save($this->request->data
//..
这是我的看法:
echo $this->Form->create('Ingredient', array ('class' => 'form', 'type' => 'file'));
echo $this->Form->input('IngredientImage.id', array ('type'=>'hidden', 'value'=> $ingredient[0]['IngredientImage']['id'],'label'=> false, 'id' => 'IngredientImage.id'));
echo $this->Form->input('IngredientImage.filename', array('type' => 'file'));
echo $this->Form->submit('Modifica', array('id'=>'edit'));
echo $this->Form->end();
请帮帮我