2016-05-01 34 views
0

我安裝了"burzum/file-storage": "^1.1"並遵循文檔CakePHP的問:Burzum /文件存儲無法保存文件

添加到了bootstrap.php中:

use Cake\Event\EventManager; 
use Burzum\FileStorage\FileStorageUtils; 
use Burzum\FileStorage\Storage\StorageManager; 
use Burzum\FileStorage\Event\LocalFileStorageListener; 


StorageManager::config('Local', [ 
    'adapterOptions' => [TMP, true], 
    'adapterClass' => '\Gaufrette\Adapter\Local', 
    'class' => '\Gaufrette\Filesystem' 
]); 

$listener = new LocalFileStorageListener(); 
EventManager::instance()->on($listener); 

我有一個表叫評論並加入此從文檔

$this->hasOne('PdfFiles', [ 
     'className' => 'Burzum/FileStorage.PdfFiles', 
     'foreignKey' => 'foreign_key', 
     'conditions' => [ 
      'PdfFiles.model' => 'Comments' 
     ] 
    ]); 

加入這種形式:

<?= $this->Form->create($comment, ['type' => 'file']) ?> 
<fieldset> 
    <legend><?= __('Edit Comment') ?></legend> 
    <?php 
     echo $this->Form->file('pdf_files.file'); 
     echo $this->Form->input('comment'); 
    ?> 
</fieldset> 
<?= $this->Form->button(__('Submit')) ?> 
<?= $this->Form->end() ?> 

添加表到我的數據庫

cake migrations migrate -p Burzum/FileStorage 

當我發送的形式文件不會在數據庫中保存在TMP文件夾,而不是。

我嘗試堅持事件。我不想使用手動版本(這是順便說一句)。

我錯過了什麼?

問候 Sundypha

+0

檢查你的php和CakePHP日誌文件。 「未保存」真的沒有意義,有助於追蹤問題。我敢打賭,有一個許可問題或類似的東西。您也可以通過事件偵聽器代碼調試以找出它沒有保存文件的位置。我知道這個插件工作的很好,所以它或多或少地取決於你找出爲什麼這些文件沒有保存在你的環境中。 – burzum

+0

是的事件似乎不會觸發。在debugKit中它缺少事件和包含的文件。我怎樣才能啓用你的插件日誌記錄? – Sundypha

+0

該插件不使用任何特殊日誌記錄,請閱讀http://book.cakephp.org/3.0/en/core-libraries/logging.html – burzum

回答

0

我詳談,如果你還需要這方面的幫助。

您需要創建另一個表我的是articlesImages你的可能是CommentDocs

<?php 

namespace App\Model\Table; 
use Burzum\FileStorage\Model\Table\ImageStorageTable; 
class ArticleImagesTable extends ImageStorageTable { 


public $actsAs = array(
    'FileStorage.UploadValidator' => array(
     'allowedExtensions' => array(
      'jpg', 
      'jpeg', 
      'png' 
     ), 
    ), 
); 
public function upload($article_id, $entity) { 

    $entity = $this->patchEntity($entity, [ 
     'adapter' => 'Local', 
     'model' => 'Articles', 
     'foreign_key' => $article_id, 
    ]); 
    return $this->save($entity); 

} 
    } 
    ?> 

//在我的文章的表,我有

$this->hasMany('ArticleImages', [ 
      'foreignKey' => 'foreign_key', 
      'conditions' => [ 
      'model' => 'Articles' 
      ] 
     ]); 

//我ArticlesController

public function upload($id = null) { 

    $entity = $this->Articles->ArticleImages->newEntity(); 
    if ($this->request->is(['post', 'put'])) { 
     $entity = $this->Articles->ArticleImages->patchEntity($entity,$this->request->data); 

     if ($this->Articles->ArticleImages->upload($id, $entity)) { 
      $this->Flash->set(__('Upload successful!')); 
     }    
    } 
    $this->set('ArticleImage', $entity); 
} 
+0

你比我想象的更好的解決方案。感謝您的解決方案,這將有助於大多數使用這個好插件的人。 – Sundypha