我正在尝试配置媒体插件(https://github.com/davidpersson/media)
核心.php 中的
require APP . 'plugins/media/config/core.php';
$xsmall = array('fitCrop' => array(75, 50));
$small = array('fitCrop' => array(75, 50));
$medium = array('fitCrop' => array(220, 140));
$large = array('fitCrop' => array(700, 335));
$xlarge = array('fitCrop' => array(700, 335));
Configure::write('Media.filter', array(
'audio' => array(),
'document' => array(),
'generic' => array(),
'image' => compact('small', 'medium', 'large'),
'video' => compact('medium', 'large')
));
从命令行我创建了初始目录
在我的用户模型中,我添加了此
class User extends AppModel {
var $name = 'User';
var $actsAs = array('Containable', 'Media.Transfer', 'Media.Generator', 'Media.Coupler');
上传表单
<!-- Display Photo Form -->
<?php echo $this->Form->create('User', array( 'controller' => 'users','action' => 'display_photo', 'type' => 'file')); ?>
<?php echo $this->Form->input('id'); ?>
<?php echo $this->Form->file('display_photo'); ?>
<?php echo $this->Form->end(array('label' => 'Upload', 'id' => 'upload-button', 'name' => 'upload-button', 'div' => false)); ?>
<!-- Form Ends -->
动作display_photo
function display_photo(){
if(!empty($this->data)) {
debug($this->data);
$this->User->save($this->data, array('fields' => array('display_photo')));
}
}
错误
SQL Error: 1054: Unknown column 'Array' in 'field list'
[CORE\cake\libs\model\datasources\dbo_source.php, line 684]
答案 0 :(得分:1)
我不确定媒体插件是否能够将文件名和目录保存在一个字段中(来自你的:display_photo)但我确定如果你添加字段basename
和dirname
(删除display_photo),我觉得应该有用。
您还需要更改显示字段以回显$ this-&gt; Form-&gt;文件('file');