I am just trying to get working LiipImagineBundle.
Ok, all I got so far:
Installed using composer
$ php composer.phar require "liip/imagine-bundle:dev-master"
Enabled bundle in AppKernel.php
new Liip\ImagineBundle\LiipImagineBundle(),
Added to routing.yml
_imagine path
Added liip_imagine filter in config.yml
Checked using php app/console router:debug and path _imagine_my_thumb exist.
But after using:
<img src="{{ '/relative/path/to/image.jpg' | imagine_filter('my_thumb') }}" />
image is not rendered, path is simply not found error.
prod.log says that Route _imagine_my_thumb does not exist, although it exist, because it's displayed using router:debug for both environments.
You know that you should replace '/relative/path/to/image.jpg' with your image path?
Make sure your file exists.
A working example
config:
liip_imagine:
driver: gd
web_root: %kernel.root_dir%/../web
data_root: %kernel.root_dir%/../app
cache_mkdir_mode: 0777
cache_prefix: /media/cache
cache: web_path
cache_clearer: true
data_loader: filesystem
controller_action: liip_imagine.controller:filterAction
formats: []
filter_sets:
avatar:
filters:
thumbnail: { size: [40, 40], mode: outbound }
profile:
filters:
relative_resize: { widen: 500 }
html:
<img src="{{ 'uploads/images/filename.jpg' | imagine_filter('avatar') }}" alt="image">
enter code here
routing.yml:
_imagine:
resource: .
type: imagine
Remark: My source folder is in the app folder (see: data_root)
I had similar problem and after enable of php_fileinfo extension in php.ini render start to work.
Related
I am using SonataUserBundle and JMSSerializerBundle and I would like to hide the token and other properties of my serialized object.
The file I want to ovvride in SonataUserBundle is Resources/config/serializer/Model.User.xml .
Here is my configuration:
app/config.yml
jms_serializer:
metadata:
auto_detection: true
directories:
- { path: %kernel.root_dir%/Resources/SoantaUserBundle/serializer, namespace_prefix: 'Sonata\UserBundle' }
- { path: %kernel.root_dir%/Resources/FOSUserBundle/serializer, namespace_prefix: 'FOS\UserBundle' }
and in app/Resources/SonataUserBundle/serializer I have tried 2 files.
Model.User.xml
<?xml version="1.0" encoding="UTF-8"?>
<serializer>
<class name="Sonata\UserBundle\Model\User" exclusion-policy="all" xml-root-name="user">
<property name="token" type="string" expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
</class>
</serializer>
Model.User.yml
Sonata\UserBundle\Model\User:
exclusion_policy: ALL
properties:
token:
expose: false
Both files dont seem to work.
I have managed to hide some properties from the FOSUserBundle, but seems I have troubles hiding the ones related to SonataUserBundle. I'm not sure if it's relevant but I would like to mention that I am using also am using HWIOauthBundle.
Any help will be greatly appreciated.
First, I don't think you need autodetection since you're specifying also the directories. Then you have a couple of typos in the sonata directory path:
jms_serializer:
metadata:
directories:
- { path: %kernel.root_dir%/Resources/SonataUserBundle/serializer, namespace_prefix: 'Sonata\UserBundle' }
I have a problem with generating relative URL in symfony 2.7 project
My project is hosted behind a proxy that redirect URL to the target VM, like this - example.com/oblounge/bo/ to vmhostname/
All my URL are generated in relative
Here is my problem
For example when I'm on this page
http://example.com/oblounge/bo/admin/articles/actualite?section=127
All generated likns are malformated, the "/admin/articles" is duplicated
http://example.com/oblounge/bo/admin/articles/admin/articles/actualite?section=127
Note: The problem is occurred only for rendered controllers
The render action
{{ render(controller('AppBundle:Back/Article/Article:sectionsArticle', { 'rubric': 'actualite' })) }}
The rendered twig
{% for section in sections %}
<li><i class="fa fa-circle-o"></i>{{ section.name }}</li>
{% endfor %}
My routing.yml
app:
resource: "#AppBundle/Controller/"
type: annotation
The prefix of my admin controller
/**
* #Route("/admin")
*/
class ArticleController extends BaseArticleController
{
I would suggest you give a look at your routing.yml file that is referenced within your bundle.
If you've already defined a prefix for the route in the routing.yml of you app/config there is no need to repeat it in the routing of your bundle , otherwise there will be a duplication of prefixes as in your case.
Example:
This is the routing.yml in the App\config folder
tutoLexikTestBundle_parents:
resource: "#tutoLexikTestBundle/Resources/config/routing/parents.yml"
prefix: /parents
And this is the one of the bundle
parents_show:
path: /{id}/show
defaults: { _controller: "tutoLexikTestBundle:Parents:show" }
I don't need to repeat the prefix 'Parents' in the path
I have a problem with the imagine_filter that works in one page and not in the others even if I use it exactly the same way with the same photo.
In the first page, where my filter works, I have this src:
http://myserver.com/media/cache/shooting/photo_preview/75/55cb71cc8ba26-00001.jpg
However, on the page where the filter doesn't work, I have this src:
:///media/cache/shooting/photo_preview/75/55cb71cc8ba26-00001.jpg
Has anybody already have a problem like that?
Moreover, the first src only works on app.php and not on app_dev.php.
On my application, I'm using Gaufrette to upload photos to S3 and then Liip to apply the filters. The cache is on my server. This is my configuration:
"liip/imagine-bundle": "1.3.*#dev",
"knplabs/gaufrette": "0.1.*",
"knplabs/knp-gaufrette-bundle": "0.1.*#dev",
"aws/aws-sdk-php": "2.8.*#dev",
<--- The services --->
services:
mycompany.aws_s3.client:
class: Aws\S3\S3Client
factory_class: Aws\S3\S3Client
factory_method: 'factory'
arguments:
-
key: %amazon_aws_key%
secret: %amazon_aws_secret_key%
region: %amazon_aws_region%
mycompany.liip_imagine.binary.loader.stream.shooting:
class: '%liip_imagine.binary.loader.stream.class%'
arguments:
- 'gaufrette://shooting/'
tags:
- { name: 'liip_imagine.binary.loader', loader: 'stream.shooting' }
<--- Gaufrette --->
knp_gaufrette:
adapters:
shooting:
aws_s3:
service_id: mycompany.aws_s3.client
bucket_name: %amazon_s3_bucket%
options:
directory: shooting
filesystems:
shooting:
adapter: shooting
alias: shooting_filesystem
stream_wrapper: ~
<--- Liip --->
liip_imagine:
resolvers:
default:
web_path: ~
shooting:
web_path:
cache_prefix: /media/cache/shooting
controller:
filter_action: mycompany_imagine.controller:filterAction
filter_sets:
photo_preview:
data_loader: stream.shooting
cache: shooting
quality: 50
filters:
upscale: { min: [690, 690] }
thumbnail: { size: [690, 690], mode: outbound}
<--- Twig --->
<img src="{{ photo.imagepath | imagine_filter('photo_preview') }}" alt="">
I got an answer on Github. I just needed to change my resolver:
https://github.com/liip/LiipImagineBundle/issues/203
I think there is a bug in the bundle LiipImagineBundle. I explain:
Here is my new config of the bundle:
liip_imagine:
resolvers:
default:
web_path:
web_root: %kernel.root_dir%/../web/img
# %kernel.root_dir%/../web/img is the folder where filtered images will be created!
cache_prefix: media/cache
# media/cache the prefix of folder where the cached images will be created
filter_sets:
cache: ~
my_thumb:
quality: 75
filters:
thumbnail: { size: [120, 90], mode: outbound }
This is the twig part for displaying the image:
{# This way the filtered image will not be created!#}
<img src="{{ 'img/test.jpg' | imagine_filter('my_thumb') }}" />
{# That way, the filted images will be created. asset() must be used. #}
<img src="{{ asset('img/test.jpg' | imagine_filter('my_thumb')) }}" />
The generated link of the image is not correct! In fact, the obtained link is:
http://localhost/media/cache/my_thumb/img/test.jpg
The expected correct link is:
http://localhost/tuto/web/img/media/cache/my_thumb/img/test.jpg
There is a missing part in the url: tuto/web/img . Is this a bug?
To avoid that problem, I did this:
<img src="{{ asset('img/test.jpg' | imagine_filter('my_thumb'))|replace({'media':'tuto/web/img/media'}) }}" />
I guess that playing with twig is not a good solution.
It is a bug in LiipImagineBundle? If not, please give the correct config for that bundle!
Thanks!
I found finally the solution on github.
I'm using Symfony 2.1 dev and looking for easiest way to get parameter from app/config/parameters.yml (ini).
Simple example:
I have record in parameters.yml
parameters:
url: "http://domain.com"
Then i want to use it somehow in static js file
var url = "{{ app.url }}"; // trying to avoid hardcode
This token should be replaced by actual value from coonfig after
app/console assetic:dump
So final js will have
var url = "http://domain.com";
Currently i'm thinking about writing my own console command but firstly i want to ensure there is no any standard way of doing such things in Symfony2 or maybe some bundle that can halp me?
UPDATE: i'd like to do this with AsseticBundle, like YUI and LESS
assetic:
debug: %kernel.debug%
use_controller: false
write_to: %kernel.root_dir%/../web
filters:
cssrewrite: ~
lessphp: ~
yui_js:
jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.6.jar"
yui_css:
jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.6.jar
to add another one filter which will replace token {{ app.url }} in js file to actual "http://domain.com"
A simple solution would be to reference your parameters in the twig globals:
parameters:
url: "http://domain.com"
an_array:
twig: "is cool"
and: "symfony2 to"
twig:
globals:
app_parameters:
url: %url%
an_array: %an_array%
Then in your template:
<script>
window.parameters = {{ app_parameters|json_encode|raw }};
</script>
would render something like:
<script>
window.parameters = {"url":"http://domain.com","an_array":{"twig":"is cool","and":"symfony2 to"}};
</script>