I'm new to symfony2 and very to use external libraries.
I want to use the KNP Snappy Bundle, my first third party bundle.
I did exactly that is told in the git link.
{
"require": {
"knplabs/knp-snappy-bundle": "dev-master"
}
}
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
//...
new Knp\Bundle\SnappyBundle\KnpSnappyBundle(),
app/config/config.yml
knp_snappy:
pdf:
enabled: true
binary: /usr/local/bin/wkhtmltopdf
options: []
image:
enabled: true
binary: /usr/local/bin/wkhtmltoimage
options: []
Then I added following line in ACME welcome controller to test
$this->get('knp_snappy.pdf')->generate('http://www.google.fr', '/Symfony/file.pdf');
It says The exit status code '1' says something went wrong:
stderr: "The system cannot find the path specified.
"
stdout: ""
command: /usr/local/bin/wkhtmltoimage --format "jpg" "http://www.google.fr" "/Symfony/file.pdf".
I tried
$this->get('knp_snappy.pdf')->generateFromHtml(
$this->renderView(
'AcmeDemoBundle:Welcome:index.html.twig'),
'/Symfony/file.pdf'
);
It shows The exit status code '1' says something went wrong:
stderr: "The system cannot find the path specified.
"
stdout: ""
command: /usr/local/bin/wkhtmltopdf --lowquality "C:\Windows\TEMP\knp_snappy530da4525584b8.92211088.html" "/Symfony/file.pdf".
What I'm missing? Do I need to install anything ? Please describe how can I run it and generate a proper pdf????? I searched, I'm guessing I need to install wkhtmltoimage etc. But from where and how?
you can also manage wkhtmltopdf with composer too, I did it in a recent project:
in your composer.json you can add:
"h4cc/wkhtmltopdf-amd64": "0.11.0-RC1"
and in your config.yml:
binary: %kernel.root_dir%/../vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64
Few months later, but here is what helped me.
I put the path to wkthmltopdf folder in escaped double quotes.
knp_snappy:
pdf:
binary: "\"C:/Program Files (x86)/wkhtmltopdf/wkhtmltopdf.exe\""
You can do one of these
1- Update your config.yml
pdf:
enabled: true
binary: wkhtmltopdf
options: []
And update your windows environment PATH with path/to/my/wkhtmltopdf
2- Or set the path directly in config.yml
pdf:
enabled: true
binary: /path/to/my/wkhtmltopdf
options: []
Related
I try to load css and js files from my symfony project and for all files I have 404.
So, I try like this :
<link href="{{ asset('css/css-theme/bootstrap.min.css') }}" rel="stylesheet">
I mention that I create the install of web :
php bin/console assets:install web --symlink
As result I have :
Trying to install assets as absolute symbolic links.
Bundle Methode/Error
FrameworkBundle absolute symlink
[OK] All assets were successfully installed
What I'm doing wrong ? Please help me. Thx in advance
Since Symfony 2.8 Assetic Bundle is not embebbed with this. You must install first your assetic bundle :
install with composer
composer require symfony/assetic-bundle
declare bundle in you appKernel
class AppKernel extends Kernel
{
// ...
public function registerBundles()
{
$bundles = array(
// ...
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
);
// ...
}
}
declare config in your config.yml
# app/config/config.yml
assetic:
debug: '%kernel.debug%'
use_controller: '%kernel.debug%'
filters:
cssrewrite: ~
You also need to dump assets via command:
php bin/console assets:dump
This physically writes all of the asset files you need for your environment. The big disadvantage is that you need to run this each time you update an asset
You can use "watch" command so that assets are regenerated automatically as they change.
php bin/console assetic:watch
More on assets management process here:
Symfony asset Documentation
Edit
Correct command for dump is.
php bin/console assetic:dump
You may also need to install "assetic" bundle via composer. With a command.
composer require symfony/assetic-bundle
And add it to your AppKernel:
public function registerBundles()
{
$bundles = array(
// ...
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
);
// ...
}
I try use dredd with symfony on windows PC.
i do next:
i create folder dredd in symfony poject
app
dredd
src
vendor
e.t.c
in symfony composer.json i add
"ddelnano/dredd-hooks-php":"dev"
Next step, i create this dredd.yml
dry-run: null
hookfiles: ./hooks.php
language: php
sandbox: false
server: null
server-wait: 3
init: false
custom:
apiaryApiKey: 'apikey '
apiaryApiName: 'apiname'
names: false
only: []
reporter: apiary
output: []
header: []
sorted: false
user: user:pass
inline-errors: true
details: true
method: []
color: true
level: info
timestamp: true
silent: false
path: []
hooks-worker-timeout: 5000
hooks-worker-connect-timeout: 1500
hooks-worker-connect-retry: 500
hooks-worker-after-connect-wait: 100
hooks-worker-term-timeout: 5000
hooks-worker-term-retry: 500
hooks-worker-handler-host: localhost
hooks-worker-handler-port: 61321
config: ./dredd.yml
blueprint: test.apib
endpoint: 'someendpoint'
and another needed file.
and dredd response
error: PHP hooks handler command not found: dredd-hooks-php Install
php hooks handler by running: $ composer require
ddelnano/dredd-hooks-php --dev
Why it does not work? What am I doing wrong?
P.S. sorry for my english.
As of now, Dredd is not officially supported on Windows. However, it should install and should work well as far as you don't need other than JavaScript hooks. Any other hooks do not work at the moment.
Support for Windows is on the roadmap though - https://github.com/apiaryio/dredd/issues/204
I'm using GrumPhp to sniff my commit in my symfony project: https://github.com/phpro/grumphp
Here is my config:
parameters:
git_dir: .
bin_dir: vendor/bin
tasks:
phpcsfixer:
config_file: ~
config: sf23
fixers: [psr2, symfony, indentation]
level: psr2
verbose: true
My question is:
Is there a way for Grumphp to automatically run php-cs-fixer when I commiting?
Yes there is!
https://github.com/phpro/grumphp/blob/master/doc/tasks.md
Since your post is a bit older here is the new updated doc, but you can still use version one! https://github.com/phpro/grumphp/blob/master/doc/tasks/php_cs_fixer2.md
You could try out this configuration but it's phpcsfixer version2!:
# grumphp.yml
parameters:
bin_dir: "./vendor/bin"
git_dir: "."
hooks_dir: ~
hooks_preset: local
stop_on_failure: false
ignore_unstaged_changes: false
process_async_limit: 10
process_async_wait: 1000
process_timeout: 60
ascii:
failed: grumphp-grumpy.txt
succeeded: grumphp-happy.txt
tasks:
phpcsfixer2:
allow_risky: false
cache_file: ~
config: ~
rules: ['#Symfony']
using_cache: true
path_mode: ~
verbose: true
Your config looks fine, what's the output ?
Do you have the cs fixer installed and configured the grumPHP config to the path of your CS fixer?
https://github.com/FriendsOfPHP/PHP-CS-Fixer#usage
GrumPHP always run php-cs-fixer with the --dry-run argument and this behavior is not configurable. You can read why here: https://github.com/phpro/grumphp/issues/110
But there's a way to automatically run php-cs-fixer: you have to install GrumPHP Extra Tasks and replace phpcsfixer2 with php_cs_auto_fixerv2 in your "grumpphp.yml" file.
Be aware that as of today GrumPHP Extra Tasks is not compatible with the latest version of GrumPHP but up to 0.17.2.
When i run the command
php app/console translation:extract en --enable-extractor=jms_i18n_routing
i get the following error:
[JMS\TranslationBundle\Exception\InvalidArgumentException]
The directory where translations are must be set.
this is the bundle configuration:
jms_i18n_routing:
default_locale: it
locales: [it, en]
strategy: prefix
cookie:
enabled: false
What is wrong with that?
You can fix this by using the --dir option to define the directory where your translations are when running your translation:extractcommand.
From the documentation,
For dumping, the bundle provides you with a console command which you
can use to update your translation files, or also just to preview all
changes that have been made.
Updating Files:
php app/console translation:extract de --dir=./src/ --output-dir=./app/Resources/translations
i had to use the following command
php app/console translation:extract en --enable-extractor=jms_i18n_routing --bundle="AcmeFooBundle" --domain="routes"
I'm trying to output a PDF of a twig file using Snappy oh my Symfony project. When I click the link my page redirects and I get the following exception:
The exit status code '1' says something went wrong:
stderr: "The system cannot find the path specified.
"
stdout: ""
command: /usr/local/bin/wkhtmltopdf --lowquality "C:\Users\user\AppData\Local\Temp\knp_snappy52333e6a9d6731.29137239.html" "C:\Users\user\AppData\Local\Temp\knp_snappy52333e6a9e84c9.03326780.pdf".
I checked the AppData folder and the html file has been rendered. There is no PDF which is what I assume Snappy is trying to generate.
I have a call similar to the following in my controller:
$html = $this->renderView('MyBundle:Foo:bar.html.twig', array(
'some' => $vars
));
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="file.pdf"'
)
);
This is my config.yml
knp_snappy:
pdf:
enabled: true
binary: /usr/local/bin/wkhtmltopdf
options: []
image:
enabled: true
binary: /usr/local/bin/wkhtmltoimage
options: []
Is there something that I have missed? I am running this on my local Windows machine, could it be a permissions error?
Most likely you have put the wrong path to the executable file.
/usr/local/bin/wkhtmltopdf - Linux path to wkhtmltopdf binary.
You must find where your wkhtmltopdf placed and set right path at config.
The issue was that I hadn't installed wkhtmltopdf, doh!