2011-07-16 105 views
0

我想配置媒體插件(https://github.com/davidpersson/mediaCakePHP的媒體插件

在命令行我創建初始目錄

在我的用戶模型中的core.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

在'display_photo'上做一個調試。我期望它會是一個多維數組。 'fields' expect'array('field_one','field_two')' – Ross

回答

1

我不知道如果媒體插件能夠保存文件名和目錄中的一個字段(從烏爾前其:display_photo )但我確信,如果你添加了字段basenamedirname(刪除display_photo),我認爲這應該工作。

你也需要改變你的顯示字段來echo $ this-> Form-> file('file');

+0

是啊謝謝..一旦我改變display_photo文件它的工作.. basename和direname是可選的,我認爲 –