on symfony 4 I use LiipImagineBundle for the display of my images.
But I noticed that there were cache problems.
My config is:
# See dos how to configure the bundle: https://symfony.com/doc/current/bundles/LiipImagineBundle/basic-usage.html
liip_imagine:
# valid drivers options include "gd" or "gmagick" or "imagick"
driver: "gd"
filter_sets:
cache: ~
# the name of the "filter set"
avatar_big:
# adjust the image quality to 75%
quality: 75
# list of transformations to apply (the "filters")
filters:
# create a thumbnail: set size to 120x90 and use the "outbound" mode
# to crop the image when the size ratio of the input differs
thumbnail: { size: [120, 120], mode: outbound }
My images are in :
public\images\avatar\
Is there a way to automatically clear the cache? I saw that there were orders to be made but I wonder if we can automate all that
If you mean to delete the cache images generated by your imagine filters, then LiipImagineBundle adds a command to Symfony console that does that:
php bin/console liip:imagine:cache:remove
Without any parameters, you will delete cache images for all paths and all filters.
You can use parameters to narrow the deletion to whatever filters and paths you want, like this:
php bin/console liip:imagine:cache:remove path1 path2 --filters=thumb1 --filters=thumb2
You have more information and examples here:
https://symfony.com/doc/current/bundles/LiipImagineBundle/commands.html#remove-cache
Related
We want to change the way we do the frontends in symfony and we'd like some level of "reflection":
We want the system to be able to detect "Template displayProduct.html.twig needs xxxx other file, defines yyyy block and uses the zzzz variable".
I would like a command similar to:
php bin/console debug:template displayProduct.html.twig
that responds something like this:
Template: displayProduct.html.twig
Requires: # And tells us what other files are needed
- widgetPrice.html.twig
- widgetAvailability.html.twig
Defines: # And tells us what {% block xxxx %} are defined
- body
- title
- javascripts_own
- javascripts_general
Uses these variables: # <= This is the most important for us now
- productTitle
- price
- stock
- language
We are now visually scanning complex templates for needed variables and it's a killer. We need to automatically tell "this template needs this and that to work".
PD: Functional tests are not the solution, as we want to apply all this to dynamically generated templates stored in databases, to make users able to modify their pages, so we can't write a test for every potential future unknown template that users will write.
Does this already exist somehow?
Hello I´m doing upload of images with vich upload and is returning the path name as.
The images were being uploaded and being displayed in the easy admin.
But then suddenly it started to not load the images anymore, and I´ve found that the destination directory was changed to ->
C:\xampp_\tmp\phpB51C.tmp
my vich mapping is like
mappings:
manchete_images:
uri_prefix: '\uploads\images\manchetes'
upload_destination: '%kernel.project_dir%/public/uploads/images/manchetes'
the images were appering normally, then suddenly start to broken to and is not creating the file upload file in the public directory
Try changing the \ in uri_prefix: '\uploads\images\manchetes' for / and try again.
Firstable as Ez mentionned you need to change the \ in uri_prefix.
Second, ther's a problem in your easy_admin configuration with the edit form.
you need to use caminhoDaImagem proprety instead of arquivoDaImagem under your form, new or edit configuration...and the file type should be changed from file to vich_file or vixh_image. ..It's already mentioned in the doc https://symfony.com/doc/master/bundles/EasyAdminBundle/integration/vichuploaderbundle.html#uploading-the-images-in-the-edit-and-new-views
easy_admin:
entities:
Product:
# ...
form:
fields:
- { property: 'imageFile', type: 'vich_image' }
I fixed your code you can see my PR
I want to realize the following thing: in my parameters.yml I have uploads_url: http://test.site.com. It's a URL to Docker container with my images. Next, I have an entity with names of this pictures.
I want to generate URL in twig like this:
background-image: url({{ 'URL from parameters' + 'name of picture from `entity`' }})
At present time I have the second part of the previous expression (name of the picture). How can I generate the 1st part?
app/config/config.yml
# Twig Configuration
twig:
globals:
url: "%url%"
app/config/parameters.yml
parameters:
url: 'your_url'
official doc How to Inject Variables into all Templates (i.e. global Variables)
twig concatenate How to concatenate strings in twig
After updating to Symfony 2.6, pages using kn._paginator no longer load:
An exception has been thrown during the rendering of a template
("Warning: file_get_contents(/Users/steve/dev/sites/virtual/newgt/
vendor/knplabs/knp-paginator-bundle/Knp/Bundle/PaginatorBundle/Resources/views
/Pagination/sliding.html.twig):
failed to open stream: No such file or directory") in
NewgtMediaBundle:Default:showSeriesSeason.html.twig at line 32
Config.yml ::
# KNP Paginator
knp_paginator:
page_range: 5 # default page range used in pagination control
default_options:
page_name: page # page query parameter name
sort_field_name: sort # sort field query parameter name
sort_direction_name: direction # sort direction query parameter name
distinct: true # ensure distinct results, useful when ORM queries are using GROUP BY statements
template:
pagination: KnpPaginatorBundle:Pagination:sliding.html.twig # sliding pagination controls template
sortable: KnpPaginatorBundle:Pagination:sortable_link.html.twig # sort link template
The requested template:
/Users/steve/dev/sites/virtual/newgt/vendor/knplabs/knp-paginator-bundle/Knp/Bundle/PaginatorBundle/Resources/views/Pagination/sliding.html.twig
actually exists at:
/Users/steve/dev/sites/virtual/newgt/vendor/knplabs/knp-paginator-bundle/Resources/views/Pagination/sliding.html.twig
How do I tell my app where knp_paginator should look for the template?
Update config.yml
knp_paginator:
....
template:
# Following two lines were present before Symfony 2.6 upgrade.
# Commented out to load from default location.
# pagination: KnpPaginatorBundle:Pagination:sliding.html.twig # sliding pagination
# sortable: KnpPaginatorBundle:Pagination:sortable_link.html.twig # sort link template
Then
sudo rm -rf app/cache/prod
app/console cache:clear –env=prod
(same for –-env=dev)
both
http://mysite/app_dev.php/media/gallery/24223?page=5&count=82&number=1752&series=FIAGT&season=2009
and
http://mysite/media/gallery/24223?page=5&count=82&number=1752&series=FIAGT&season=2009
are working again.
I defined some values in the define.yml in the app/config folder.
And I can access then in the PHP code.
Now I want to use the validate.yml file to check weather users give out too many data, could I use the configed valus in the config file(such as %maxInputLength%) rather than write it one more time in the
validate.yml?
for a example:
I defind a variable in define.yml:
maxLength: 10
So we can use it in the controller.
But if I want to use it in the validate.yml in my own bundle,
such as : myBandle/config/validation.yml
Now I just use the file like that:
myBundle\Entity\UserDesc:
properties:
content:
- NotBlank: ~
- MaxLength: 10
So it seems that the same value was defined at two place.In fact the 10 in the second file is just the value defined in the first file . But I don't know how to get the value from the first file.Is there any way to make that?
AFAIK you want to set value to variable in one config file and then reuse it in other .yml config file.
So you cant define some vars in e.g variables.yml file
parameters:
test_variable: "blabla"
Then in second .yml config file you can import file with defined variables:
imports:
- { resource: variables.yml }
Then you can use imported variable in this file:
property:
some_value: %test_variable%