索纳塔媒体捆绑没有图像预览

时间:2015-01-22 13:31:10

标签: symfony sonata-admin sonata-media-bundle

我的Sonata Media捆绑包有问题。我在服务器(本地)上传的图像不会显示(缩略图丢失)。我检查了路径并且它都是正确的。我上传的所有图片都会转移到目录/web/ uploads/media

检查屏幕截图:

enter image description here

Full size screenshot here

配置文件:

sonata_media:
    # if you don't use default namespace configuration
    #class:
    #    media: MyVendor\MediaBundle\Entity\Media
    #    gallery: MyVendor\MediaBundle\Entity\Gallery
    #    gallery_has_media: MyVendor\MediaBundle\Entity\GalleryHasMedia
    default_context: default
    db_driver: doctrine_orm # or doctrine_mongodb, doctrine_phpcr
    contexts:
        default:  # the default context is mandatory
            providers:
                - sonata.media.provider.dailymotion
                - sonata.media.provider.youtube
                - sonata.media.provider.image
                - sonata.media.provider.file

            formats:
                preview:   { width: 100, quality: 100}
                small: { width: 100 , quality: 70}
                big:   { width: 500 , quality: 70}

    cdn:
        server:
            path: uploads/media

    filesystem:
        local:
            directory:  %kernel.root_dir%/../web/uploads/media
            create:     false

sonata_notification:
    backend: sonata.notification.backend.runtime

sonata_notification:
    admin:
        enabled: false

我在Sonata管理包中使用了Media bundle,并且所有工作都很好但只是没有渲染缩略图。我阅读了Media BUndle doc Helper部分,但不明白。

在我的ArticleAdmin控制中,我添加了这样的文件:

/**
 * Configure Form Fields
 *
 * Fields to be shown on create/edit forms
 */
protected function configureFormFields(FormMapper $formMapper)
{
    $link_parameters = array();

    if ($this->hasParentFieldDescription()) {
        $link_parameters = $this->getParentFieldDescription()->getOption('link_parameters', array());
    }

    if ($this->hasRequest()) {
        $context = $this->getRequest()->get('context', null);

        if (null !== $context) {
            $link_parameters['context'] = $context;
        }
    }
$formMapper->add('media', 'sonata_type_model_list', array('required' => false), array(
                'link_parameters' => $link_parameters
           ))
}

任何解决方案?


更新

在我的日志文件中,我发现了这个:

  

[2015-01-22 15:28:22] request.ERROR:未捕获的PHP异常   Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException:" No   为" GET找到的路线   /admin/sonata/media/media/uploads/media/default/0001/01/thumb_1_admin.jpeg""   在C:\ xampp \ htdocs \ Symfony \ app \ cache \ dev \ classes.php line 2017   {"例外":" [对象]   (Symfony的\元器件\ HttpKernel \异常\ NotFoundHttpException(代码:   0):找不到\" GET的路由   /admin/sonata/media/media/uploads/media/default/0001/01/thumb_1_admin.jpeg\"   在C:\ xampp \ htdocs \ Symfony \ app \ cache \ dev \ classes.php:2017,   Symfony的\分量\路由\异常\ ResourceNotFoundException(代码:   0):at   C:\ XAMPP \ htdocs中\的Symfony \应用\缓存\ dev的\ appDevUrlMatcher.php:521)"}   []

4 个答案:

答案 0 :(得分:0)

您的链接应该是' / uploads / media /....'而不是上传/媒体/...&# 39;

在配置文件中,更改

CDN:     服务器:         路径:上传/媒体

CDN:     服务器:         路径:/ uploads / media

希望它有助于解决您的问题。

答案 1 :(得分:0)

除了Stiff Roy的回答,您可以将虚拟主机根设置为Symfony / web(在您的情况下)。

所以,当你在http://localhost/app_dev.php/admin/sonata/media/media/list时 您的图片加载为http://localhost/uploads/media/default/0001/01/thumb.jpg

错误"No route found for "GET /admin/sonata/media/media/uploads/media/default/0001/01/thumb_1_admin.jpeg""表示它试图通过控制器而不是直接访问来加载图像。有关设置env的其他信息可以在herehere(PHP Storm)中找到。

答案 2 :(得分:0)

需要更改config.yml中的路径

sonata_media
    cdn:
        server:
            path: /myproject/web/uploads/media

答案 3 :(得分:0)

好的,所以我用这种方式解决了问题:

  sonata_media:
# if you don't use default namespace configuration
#class:
#    media: MyVendor\MediaBundle\Entity\Media
#    gallery: MyVendor\MediaBundle\Entity\Gallery
#    gallery_has_media: MyVendor\MediaBundle\Entity\GalleryHasMedia
db_driver: doctrine_orm # or doctrine_mongodb, doctrine_phpcr it is mandatory to choose one here
default_context: default # you need to set a context
contexts:
    default:  # the default context is mandatory
        providers:
            - sonata.media.provider.dailymotion
            - sonata.media.provider.youtube
            - sonata.media.provider.image
            - sonata.media.provider.file
            - sonata.media.provider.vimeo

        formats:
            small: { width: 100 , quality: 70}
            big:   { width: 500 , quality: 70}

cdn:
    server:
        path: "/uploads/media" # http://media.sonata-project.org/

filesystem:
    local:
        directory:  "%kernel.root_dir%/../web/uploads/media"
        create:     false

并在控制台中:$ php app / console server:start

symphony环境app_dev无法使用奏鸣曲媒体包。

干杯