Compile Error: Declaration of FOS\RestBundle\Request\RequestBodyParamConverter::apply() must be compatible with that of Sensio\Bundle - php

I'm using symfony2. I'm trying to use the Request Body convert listener from FriendsOfSymfony bundle. I have enabled the request converters on sensio_framework_extra and when enabling the body converter:
fos_rest:
body_converter:
enabled: true
I get this exception:
FatalErrorException: Compile Error: Declaration of FOS\RestBundle\Request\RequestBodyParamConverter::apply() must be compatible with that of Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface::apply() in /var/www/xxx/vendor/friendsofsymfony/rest-bundle/FOS/RestBundle/Request/RequestBodyParamConverter.php line 32
in /var/www/xxx/vendor/friendsofsymfony/rest-bundle/FOS/RestBundle/Request/RequestBodyParamConverter.php line 32
at ErrorHandler->handleFatalError(object(ExceptionHandler), array('type' => '64', 'message' => 'Declaration of FOS\RestBundle\Request\RequestBodyParamConverter::apply() must be compatible with that of Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface::apply()', 'file' => '/var/www/xxx/vendor/friendsofsymfony/rest-bundle/FOS/RestBundle/Request/RequestBodyParamConverter.php', 'line' => '32')) in /var/www/xxx/vendor/symfony/symfony/src/Symfony/Component/Debug/ErrorHandler.php line 212
Here is my full config.yml file
imports:
- { resource: parameters.yml }
- { resource: security.yml }
framework:
#esi: ~
#translator: { fallback: "%locale%" }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver, add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
# Friends of Symfony configuration
fos_rest:
body_converter:
enabled: true
routing_loader:
default_format: json
param_fetcher_listener: true
body_listener: true
format_listener: true
view:
view_response_listener: 'force'
# Sensio Framework Extra Configuration
sensio_framework_extra:
request: { converters: true }
view: { annotations: false }
router: { annotations: false }
and this is my require libraries on composer.json
"require": {
"php": ">=5.3.3",
"symfony/symfony": "~2.4",
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "~1.2",
"twig/extensions": "~1.0",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~2.3",
"sensio/framework-extra-bundle": "~3.0",
"sensio/generator-bundle": "~2.3",
"incenteev/composer-parameter-handler": "~2.0",
"friendsofsymfony/rest-bundle": "1.1.0",
"jms/serializer-bundle": "dev-master"
},
anybody has any ideas?
thanks

Related

Adding property to Symfony BaseModel

I have the below symfony model and I need to add a name property (see below) to the existing model and then update the database accordingly. What is the proper way to accomplish this? I appreciate any suggestions.
I tried running php bin/console doctrine:database:drop and then php bin/console doctrine:database:create, hoping it'll make the necessary mappings, without any success, I am getting the following error: You have requested a non-existent service "doctrine".
This seems to be overly complicated and I am sure theres a simpler way to accomplish this. I appreciate any suggestions.
composer.json snippet
"php": ">=5.5.9",
"symfony/symfony": "3.0.*",
"doctrine/orm": "^2.5",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/doctrine-cache-bundle": "^1.2",
"symfony/swiftmailer-bundle": "^2.3",
"symfony/monolog-bundle": "^2.8",
"sensio/distribution-bundle": "^5.0",
"sensio/framework-extra-bundle": "^3.0.2",
NoticeSettings.php
<?php
namespace AppBundle\Model;
class NoticeSettings extends BaseModel
{
protected $table = "notice_settings";
/**
* #Assert\Type(type="string")
*/
protected $notice;
/**
* #Assert\Type(type="string")
*/
protected $name;
}
config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
parameters:
locale: en
uploads_directory: '%kernel.root_dir%/../uploads'
framework:
#esi: ~
#translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
fragments: ~
http_method_override: true
assets:
version: 15
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
form_themes: ["form/fields.html.twig"]
globals:
user: "#app.user"
badges: '#app.sidebar_badges'
paths:
'%kernel.root_dir%/../src/AppBundle/Resources/views': ~
'%kernel.root_dir%/../src/AppBundle/Resources/TwigBundle/views': 'Twig'
It looks like Doctrine is not fully configured in your application. This is likely also why the service can not be found.
Please make sure that inside your AppKernel.php the DoctrineBundle is registered (search for new Doctrine\Bundle\DoctrineBundle\DoctrineBundle()).
Next you will need the doctrine configuration. You can check the repository if you need a reference configuration:
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
Also make sure, that your parameters.yml and parameters.yml.dist contain the values needed by the configuration. Again you can take the file from the official repository as a reference.

symfony2 ("There is no "cssrewrite" filter.") in "base.html.twig"

Small question. I'm learning the symfony2 framework and I get this error
An exception has been thrown during the compilation of a template ("There is no "cssrewrite" filter.") in "base.html.twig".
Do I have to manually activate it somewhere or went there something wrong with the installation processes (running it on windows). Can someone point me in the right direction?
twig:
{% block stylesheets %}
{% stylesheets filter='cssrewrite'
'%kernel.root_dir%/../vendor/twbs/bootstrap/dist/css/bootstrap.css'
'%kernel.root_dir%/../vendor/twbs/bootstrap/dist/css/bootstrap-theme.css'
'#blogBundle/Resources/public/css/costom.css'
%}
<link rel="stylesheet" href="{{ asset_url }}"/>
{% endstylesheets%}
{% endblock %}
framework:
secret: xxxxxxxxxx
router: { resource: "%kernel.root_dir%/config/routing.yml" }
templating: { engines: ['twig', 'php'] }
config.yml file
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: "#blogBundle/Resources/config/services.yml" }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
#translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
Since Symfony3, assetic is not included by default, you must install it using composer (which I suspect you did). But you also need to add it to your config.yml like this:
assetic:
debug: "%kernel.debug%"
use_controller: "%kernel.debug%"
bundles: []
filters:
cssrewrite: ~

Symfony2 FosUserBundle is loosing session

I am using FosUserBundle to register and authenticate users in my website. But i am having troubles with it cause user session is loosen very soon. Sometimes 5 minutes, sometimes 10 minutes, and then user is redirected to the login form again, causing many users to left my website.
This is what i currently have in my project:
composer.json
{"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.6.*",
"doctrine/orm": "~2.2,>=2.2.3,<2.5",
"doctrine/dbal": "<2.5",
"doctrine/doctrine-bundle": "~1.2",
"twig/extensions": "~1.0",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"symfony/yaml": "2.7.*#dev",
"symfony/filesystem": "~2.6",
"sensio/distribution-bundle": "~3.0,>=3.0.12",
"sensio/framework-extra-bundle": "~3.0,>=3.0.2",
"incenteev/composer-parameter-handler": "~2.0",
"friendsofsymfony/user-bundle": "~2.0#dev",
"friendsofsymfony/jsrouting-bundle": "#stable",
"knplabs/knp-snappy-bundle": "dev-master",
"jms/serializer-bundle": "0.13.*"
},
"require-dev": {
"sensio/generator-bundle": "~2.3"
}
}
config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: "#MoovityUserBundle/Resources/config/services.yml" }
- { resource: "#MoovityBackendBundle/Resources/config/services.yml" }
framework:
#esi: ~
translator: { fallback: "%locale%" }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
cookie_lifetime: 0
gc_maxlifetime: 14400
fragments: ~
http_method_override: true
# translator: ~
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ MoovityBackendBundle ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver, add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
fos_user:
db_driver: orm
firewall_name: main
user_class: Moovity\UserBundle\Entity\User
registration:
confirmation:
enabled: true
from_email:
address: noreply#mywebsite.com
sender_name: mywebsite
template: MoovityBackendBundle:Mail:mail_fos_user_register_template.html.twig
# template: FOSUserBundle:Registration:email.html.twig
form:
type: moovity_user_registration
resetting:
email:
from_email:
address: resetpass#mywensite.com
sender_name: My Website Reset Password
template: FOSUserBundle:Resetting:email.html.twig
form:
type: moovity_user_resetting
service:
mailer: fos_user.mailer.twig_swift
#fos_rest:
# routing_loader:
# default_format: json
security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
# id: fos_user.user_provider.username
id: fos_user.user_provider.username_email
firewalls:
main:
pattern: ^/
form_login:
login_path: fos_user_registration_register
check_path: fos_user_security_check
provider: fos_userbundle
csrf_provider: form.csrf_provider
# always_use_default_target_path: true
# Redirección despues de loguear
default_target_path: moovity_backend_homepage
logout:
path: fos_user_security_logout
target: fos_user_registration_register
# target: fos_user_security_login
anonymous: true
security: true
remember_me:
key: 57361cdee0bb68f4e4b71f06b28fc07e
lifetime: 6000
What am i doing wrong?
Ok, i have noticed that fosuserbundle is loosing session with Symfony 2.6, so i switched to 2.3 and now it seems to be working.
Thank you very much.
I think the problem is the translation.
Got the same errors, try to remove the locale in your parameter and reset it with ~
Please post if it was the problem

How to use global variable in symfony twig file?

I have done setting in app/config/config.yml
twig:
globals:
mandatory_note: %mandatory_note%
parameter also set in config.yml file
parameters:
mandatory_note: "Note: * marked fields are mandatory"
And in twig file I have accessed the variable
{{ mandatory_note }}
but still gets error. ie. mandatory_note variable doesnot exists.
This is my config.yml file
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
framework:
#esi: ~
translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
cookie_lifetime: 0
gc_maxlifetime: 36000
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: []
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
unix_socket: "/opt/lampp/var/mysql/mysql.sock"
charset: UTF8
mapping_types:
enum: integer
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
encryption: "%mailer_encryption%"
port: "%mailer_port%"
sender_address: "%mailer_sender%"
parameters:
max_contents_per_page: 20
max_pages_per_page: 10
mandatory_note: "Note: * marked fields are mandatory"
twig:
globals:
mandatory_note: %mandatory_note%
You need to put it under Twig. Like that:
twig:
globals:
mandatory_note: %mandatory_note%
Also make sure that mandatory_note is defined in parameters.yml file. To test if global works just use "testString" instead of %mandatory_note%
What if you put them together, like this?
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
globals:
mandatory_note: "%mandatory_note%"
I got solution, I added below code in parameters.yml file:
parameters:
mandatory_note: "Note: * marked fields are mandatory"
twig:
globals:
mandatory_note: "%mandatory_note%"
and it's working finally.

Clear Cache: You have requested a non-existent service "sensio_distribution.webconfigurator"

When run app/console cache:clear, no problem. But when I try to clear prod cache (app/console cache:clear --env prod) I get:
[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException] You have requested a non-existent service "sensio_distribution.webconfigurator".
I dont have the first clue what am I doing wrong.
my config:
imports:
- { resource: parameters.yml }
- { resource: security.yml }
framework:
#esi: ~
#translator: { fallback: "%locale%" }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver, add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
# Propel
propel:
dbal:
#driver: "%database_driver%"
driver: "%database_driver%"
user: "%database_user%"
password: "%database_password%"
dsn: "mysql:host=localhost;dbname=symfony;charset=UTF-8%"
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
# FOS
fos_user:
db_driver: propel
firewall_name: main
user_class: FOS\UserBundle\Propel\User
Remove manually all directories under app/cache/

Categories