I use VichUploaderBundle for upload my media files and I want to use AvalancheImagineBundle to create thumbs in my templates.
How it should be done?
I have this right now:
<td><img src="{{ vich_uploader_asset(entity, 'image') | apply_filter('my_thumb')}}" alt="{{ entity.nombre }}" /></td>
But the output is:
<img src="/app_dev.php/media/cache/my_thumb/images/uploads/392158_10150441208223772_580903771_8591661_774015725_n.jpg" alt="Froga"/>
this is my config.yml:
# Vich Uploader
vich_uploader:
db_driver: orm
twig: true
gaufrette: false # set to true to enable gaufrette support
storage: vich_uploader.storage.file_system
mappings:
uploads:
uri_prefix: /images/uploads
upload_destination: %kernel.root_dir%/../web/images/uploads
namer: ~ # specify a file namer service id for this entity, null default
directory_namer: ~ # specify a directory namer service id for this entity, null default
delete_on_remove: true # determines whether to delete file upon removal of entity
inject_on_load: true # determines whether to inject a File instance upon load
avalanche_imagine:
source_root: %kernel.root_dir%/../web/images/uploads
web_root: %kernel.root_dir%/../web/images/uploads
cache_prefix: media/cache
driver: gd
filters:
my_thumb:
type: thumbnail
options: { size: [120, 90], mode: outbound, quality: 100, format: png }
Any help or clue?
If the problem you are having is that no image is being displayed, then I had the same issue.
In order to solve it I ensured that within my config.yml, the source_root and web_root options of avalanche_imagine were set to %kernel.root_dir%/../web (or your web root). Here is the relevant snippet from my config.yml:
#Uploads
knp_gaufrette:
adapters:
article_adapter:
local:
directory: %kernel.root_dir%/../web/images/articles
filesystems:
article_image_fs:
adapter: article_adapter
vich_uploader:
db_driver: orm
gaufrette: true
storage: vich_uploader.storage.gaufrette
mappings:
article_image:
uri_prefix: /images/articles
upload_destination: article_image_fs
namer: vich_uploader.namer_uniqid
#images
avalanche_imagine:
filters:
article_list:
type: thumbnail
options: { size: [100, 100], mode: outbound }
source_root: %kernel.root_dir%/../web
web_root: %kernel.root_dir%/../web
cache_prefix: cache
Nothing wrong with that. Imagine bundle in production generates thumbnail the first time its called and stores it in web/media folder. On second call it just reads from web/media.
It has some advantages to modify the thumnail sizes at will. If You are worried about performance you should fire some job to generate thumbnail after the upload is finished,
although i used it like that and never complained.
In my case, I chose to use LiipImagineBundle which is a fork of the AvalancheImagineBundle
.
I were configure this bundle to use gaufrette as data-loader, than it simple to use it as you describe, without caring much about the paths.
Related
Im using vich uploader to upload images and oneup flysystem file abstraction. Also liip imagine bundle to make thumbnails.
The problem is that liip takes my oneup flysystem adapters local path and tries to find uploads/58998d6502406.png image in it. When i remove uploads prefix, then it works else throws source file not found exception.
Maybe i am missing something in my configuration?
Twig:
<img src="{{ vich_uploader_asset(partner, 'imageFile') | imagine_filter('my_thumb') }}" /> (also tried with asset)
generated url:
http://app.dev/media/cache/resolve/my_thumb/uploads/58998d6502406.png
url that works:
http://app.dev/media/cache/resolve/my_thumb/58998d6502406.png
My configuration:
# OneupFlysystem Configuration
oneup_flysystem:
adapters:
uploads_adapter:
local:
directory: "%kernel.root_dir%/../web/uploads"
filesystems:
uploads_fs:
adapter: uploads_adapter
mount: uploads_fs
# Vich uploader Configuration
vich_uploader:
db_driver: orm
storage: flysystem
mappings:
partner_image:
uri_prefix: /uploads
upload_destination: uploads_fs
namer: vich_uploader.namer_uniqid
delete_on_remove: true
delete_on_update: true
news_image:
uri_prefix: /uploads
upload_destination: uploads_fs
namer: vich_uploader.namer_uniqid
delete_on_remove: true
delete_on_update: true
# Liip imagine bundle Configuration
liip_imagine:
loaders:
uploaded_images:
flysystem:
filesystem_service: oneup_flysystem.uploads_fs_filesystem
data_loader: uploaded_images
filter_sets :
my_thumb:
filters:
thumbnail: { size: [120, 90], mode: outbound }
Fixed by changing uri_prefix in vich uploader config to empty string uri_prefix: ""
I have my model entities saved in src/AppBundle/Model/Entity.
You can understand, that i have own custom folder for entities (in model folder).
This is my orm settings in config.yml:
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: false
mappings:
user:
type: annotation
dir: %kernel.root_dir%/../src/AppBundle/Model/Entity
alias: 'Entity'
prefix: AppBundle\Model\Entity
is_bundle: false
I have a problem with these lines in my security.yml:
providers:
our_db_provider:
entity:
class: AppBundle:User
property: username
# if you're using multiple entity managers
# manager_name: customer
There is some error:
Unknown Entity namespace alias 'AppBundle'.
I don't what ref I have to use (AppBundle:User probably not).
Thank you for your answers.
By default, all Symfony bundles will have a nice alias: XxxBundle (aliasing the NamespaceOfXxxBundle\Entity namespace). As you're bundle doesn't follow this convention and stores it in Model\Entity instead, you have 2 options:
Don't use the alias feature and pass the FQCN: AppBundle\Model\Entity\User
Create a new alias, give it a nice name and use it:
doctrine:
orm:
# ...
mappings:
user:
type: annotation
dir: %kernel.root_dir%/../src/AppBundle/Model/Entity
alias: App # <-- the alias name
prefix: AppBundle\Model\Entity
is_bundle: false
App:User
Im trying to add parameters.yml.dist inside config.yml this way:
- { resource: parameters.yml }
- { resource: parameters.yml.dist }
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
globals:
base_url_algoritmo: %base_url_algoritmo% <<<<<<< this parameter is inside paramters.yml.dist
but I get
[Symfony\Component\Config\Exception\FileLoaderLoadException]
Cannot load resource "parameters.yml.dist".
".dist" is used only for distribution (dummy data that will be used on composer install/update) - so this idea of including it in config.yml is not so good ;)
I am trying to setup a parent child relationship and I can't seem to get the mapping config right. I'm using Symfony2.5, FOSElastica 3.0.9 and Elasticsearch 1.4.4
Here is the relevent section from my mapping:
# fos elastica
fos_elastica:
clients:
default: { host: 127.0.0.1, port: 9200 }
serializer:
callback_class: FOS\ElasticaBundle\Serializer\Callback
serializer: serializer
indexes:
index:
index_name: index_%kernel.environment%
client: default
types:
company:
mappings:
id:
type: "long"
company_name:
type: "string"
fields:
raw:
type: "string"
index: "analyzed"
index_analyzer: "sortable"
persistence:
elastica_to_model_transformer:
ignore_missing: true
driver: orm # orm, mongodb, propel are available
model: Alpha\RMSBundle\Entity\Company
provider: ~
finder: ~
listener: ~
serializer:
groups: [company]
job:
mappings:
id:
type: "long"
company:
type: "object"
properties:
id:
type: "long"
_parent:
type: company
property: company
identifier: id
#_routing:
# required: true
# path: company
persistence:
elastica_to_model_transformer:
ignore_missing: true
driver: orm # orm, mongodb, propel are available
model: Alpha\RMSBundle\Entity\JobOpening
provider: ~
finder: ~
listener: ~
serializer:
groups: [job]
First I populate company, but when I try to populate job I get the following error:
[Elastica\Exception\ResponseException]
RoutingMissingException[routing is required for [index_v2]/[job]/[1]]
I have tried specifying the routing which is commented out above, but that didn't set the relationship either, I have taken the routing out as it is not mentioned in the docs.
Can anyone see where I am going wrong?
There is no problem with the mapping above, and _routing is not required. However FOSElastica will not populate the mapping with a _parent set.
However, as the docs says you need to to use setParent on the Document. In order to do this I need to setup a custom ModelToElasticaTransformer. This can be done by extending the ModelToElasticaAutoTransformer provided from the bundle in a class Alpha\RMSBundle\Transformer\JobToElasticaTransformer
In the transform() function I inserted a line:
$document->setParent($object->getCompany()->getId());
just above
return $document
Then you declare the service:
alpha.transformers.model.job:
class: Alpha\RMSBundle\Transformer\JobToElasticaTransformer
calls:
- [ setPropertyAccessor, ['#fos_elastica.property_accessor'] ]
Finally add the following in the mapping for the type in the persistence section:
model_to_elastica_transformer:
service: alpha.transformers.model.job
Now you can use populate as normal, as long as you remember to populate the parent class first
The bundle explains this very clearly in it's documentation
Note that to create a document with a parent, you need to call
setParent on the document rather than setting a _parent field. If you
do this wrong, you will see a RoutingMissingException as Elasticsearch
does not know where to store a document that should have a parent but
does not specify it.
I have this this config:
liip_imagine:
resolvers:
default:
web_path: ~
filter_sets:
cache: ~
subitem_in_category:
path: ~ ///how to change the default path where the images are saved?
filters:
my_custom_filter: { }
relative_resize: { heighten: 210 }
Im trying to change the name of the directory wheren the images are saved, but I get
InvalidConfigurationException: Unrecognized options "path" under
"liip_imagine.filter_sets.subitem_in_category"
I have read this: https://github.com/liip/LiipImagineBundle/blob/master/Resources/doc/configuration.md
The features was removed some time ago for bad design about component dependency. See this pull request for further motivations about this.
For the same features suggest to configuring several resolvers, as described here:
liip_imagine:
resolvers:
foo:
web_path:
cache_prefix: foo
bar:
web_path:
cache_prefix: bar
filter_sets:
foo:
cache: foo
bar:
cache: bar
Else you can use an old branch of the bundle.
Hope this help